Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How best to organize python scripts?

best organize Python scripts
0
Posted

How best to organize python scripts?

0

The key phrase is “stare into a folder”; this implies that you are storing all of your files in a single folder. If you organize your files in a hierarchical fashion, using sub-folders, you might find yourself with only one or two scripts in a “bottom level” folder. If these are named correctly, it should be obvious what they do. For example, you might start by having “university work” and “outside work” folders at the top level. Outside work may then be partioned by project, while the University folder can be subdivided by course/unit/module.

0
10

Good naming, an overview document that you can easily access (notepad, google docs, whatever tool you’re using for this), and usage texts in the scripts that are printed if you run the script with no arguments. (If you’re using module-level docstrings for the help text, you can use standard documentation tools to generate the index for you, or even write your own little indexing tool.) I often write task-oriented notes as well, with transcripts of real sessions to show how the tools are used. Just cutting and pasting a session to a text file can be good enough — seeing what you did three month earlier can be a great help when you’re trying to do a similar thing again. Or mail the transcripts to yourself, so you have them sitting in a mail folder. (This has nothing to do with formal CS education, of course.

0

One thing I struggled with when I started with Python was being able to import my own work. Because I couldn’t figure it out for a long time, I left everything I needed in one folder. The trick to importing stuff is to organize the scripts into sensible groups, make folders from the groups and then put an empty file called __init__.py in each folder so Python knows that’s a module and lets you import from it. The easiest/ laziest thing is to just make a folder under your site-packages directory (which lives under Python25/lib on Windows) with your initials or something and then put your folders under that.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123