Describe python "project" structure - Python Help - Discussions on Python.org
Describe python "project" structure Python Help anneranch (Jim ) July 4, 2023, 6:56pm 1 Would it be possible for somebody very briefly describe what each folder in python file structure does ? I can deduct that “src” contains source files… What I do not get is - what contains GUI (windows) _ and what contains code which does processing and why. I like to know this when I add new function to the application - what goes in what sub folder.
Screenshot from 2023-07-04 13-47-29|294x500](upload://l41RW9Mqo9XcoWiWg2wsfFQLMlE.png) kknechtel (Karl Knechtel) July 4, 2023, 8:08pm 2 There is no set “python file structure”, and folders do not “do” anything at all except to contain files. If you are using certain tools or libraries, they might expect specific things to be in specific folders; see the documentation for details. However, there are some basic recommendations for how to organize a Python project, that are useful for packaging and distribution (this means: making it possible for others to install your code easily, either from e.g. a Github repository or from uploading it to PyPI.
This is much too complex to explain in a single post, but there is a full guide offered by the Python Packaging Authority: petersuter (Peter Suter) July 5, 2023, 10:55pm 3 Somehow your image didn’t show. Screenshot from 2023-07-04 13-47-29.png 339×575 25.3 KB Looks like you are talking about https://github.com/NanoVNA-Saver/nanovna-saver/tree/main/src/NanoVNASaver The folders are specific to that project. That’s just how they chose to organize their functions.
Other projects will use a completely different structure. anneranch (Jim ) July 6, 2023, 2:03am 4 Thanks for your reply. I am well aware there is no common way to organize Python project. Confirming that was not the reason why I posted this. I am trying to add function / class to the project and was looking for explanations on HOW is current project organized. I am just reading current project and its layout looks as it has GUI code and then "action / process " code in separate folders.
I just need confirmation that my guess is “close enough”… and it is relatively unimportant where the code came from and what it does. fungi (fungi) July 6, 2023, 12:16pm 5 Out of curiosity, if you don’t already know the answer to your question, how can you be sure what information is required to arrive at an answer? As for an answer: If you’re going to be contributing your additions back to the community which maintains the software you’re altering then they’re the ones in the best position to indicate the most optimal placement.
If you’re not planning to contribute it to them, then you can pretty much put it wherever is most convenient for you. It’s a subjective question after all, so pretty much any answers you get are going to be opinions… how do you decide whose opinion is the best one? anneranch (Jim ) July 6, 2023, 4:24pm 6 how can you be sure what information is required to arrive at an answer? My answer is very simple - I work with what I have and make the best guess.
If the source covers / answers everything 100 % I would pick another hobby… Since the software I am trying to “reverse engineer” does not include anything describing the project folders I am pretty much on my own. The “stuff” on giothuiub is also pretty much abandoned… Yes there are some “fixes” but that doe sno help much. As I said - I like to add another function / functionality to the project and since it is my first attempt using Python I am just curios how to oganoize / where to add my stuff.
I prefer to add my stuff in a separate place , such as a new folder etc. Yes , I can add “new project” using PyCharm but that is very minimal as far as organization and using folders. Basically I would like to have this initialize project - such as clone etc. subfolder - version control project classes – including main subfolder - classes additions class functions / process database That is what I like to see as "project structure ". fungi (fungi) July 6, 2023, 6:03pm 7 If your preference is to put your additional Python module (*.py) files in a subdirectory, that can definitely be made to work.
Keep in mind that each directory containing module files is itself an “import package” in Python parlance. That is implicit behavior by default, but you can make it explicit by adding (even an empty) __init__.py file in the directory containing your module files. For example: originalpackage/__init__.py originalpackage/somemodule.py originalpackage/anothermodule.py originalpackage/mysubpackage/__init__.py originalpackage/mysubpackage/mymodule.py originalpackage/mysubpackage/myothermodule.py Then anything using these can access their contents by using the . operator in import statements, like (just one of many ways): import originalpackage.mysubpackage.mymodule Rosuav (Chris Angelico) July 6, 2023, 7:36pm 8 If you want a solid structure into which you put your own code, I’d recommend having a look at Django - it’s one of the most popular Python web frameworks and tends to work in that sort of style.
But not everything does, so you’ll much more commonly find that the structure of a project is defined by the project, not by the language or framework you’re using. Python is not Java; we don’t need shackles and boilerplate and rigid structure. bryevdv (Bryan Van de Ven) July 6, 2023, 8:15pm 10 This is a pretty far-fetched and unjustified accusation to level at someone for merely observing that there exists a diverse range of needs for the huge Python ecosystem [1] , as a whole.
Which spans: finance, medicine, several engineering disciplines, academic research, HPC computing, web development, SAAS infrastructure, data science and ETL,… just off the top of my head. ↩︎ anneranch (Jim ) July 6, 2023, 8:32pm 11 accusation?? I give up… fungi (fungi) July 6, 2023, 9:59pm 12 I can’t speak to Pycharm or other IDEs since I stick to command line tools (comfortable Unix/POSIX user since the 80s), but generally speaking rearranging the files in an existing project has implications on how the objects defined within those files and the modules or import packages they comprise are accessed, even from within other files in that same codebase.
Any reorganization made without taking necessary edits of those files’ contents into account will quite possibly alter its internal API in ways which render the whole nonfunctional. Also, “you can organize your project however you like” isn’t necessarily the same thing as “you must write spaghetti code and bake in your job security.” The point was that you’re allowed to, for example, have multiple classes in a single file (or not even use classes at all if you don’t want, Python doesn’t mandate a specific coding paradigm like OO or pure functions or whatever), split things up into arbitrary groups in different files or directories, et cetera, stitched together with simple import statements.
The language doesn’t prevent you from organizing your work poorly, but it also doesn’t try to force someone else’s opinions on you as to what well-organized code means. In case it hasn’t been clear in your reading so far, the Python language is a scripting language, so more akin to languages like Perl, PHP or Bourne/Korn/C Shell than to something like C++ or Java. It’s design goals focus more on readability, flexibility and comprehensive toolsets without being overly opinionated on style (syntactically relevant elements aside) or insisting on specific coding patterns. anneranch (Jim ) July 7, 2023, 8:40pm 13 There was a reason for asking about python " project " structure.
The application I am working with starts with “about” info , which I do not see when I run it as “normal” from executable , not using IDE. After “about” it runs “main”… Apparently that is OK, but a little confusing when trying to logically “step” through the application. I was
The rest of this page is on the live site.