2

Yesterday I started an important Python project and since then I've been searching for documentation on how to organize the code to have a "high-quality" project. There is a lot of articles and official documentation about how to organize packages and modules but, as I'm very new to this language, I think that is not my case.

The project is a client-server platform to distribute files in a local network (ok, is a lot more than this but its the basic idea). The thing is that is not going to be a module and I think that is not a package. At least not as described in the Python documentation:

Packages are a way of structuring Python’s module namespace by using “dotted module names”

I searched too in Git to see what popular project do to organize its code but most of them are modules and the rest... I don't even know how to run them.

So the question is, what is my code (module, package, ...) and which is the best way to organize it? Do you know any good article about this?

Thank you.

1 Answer 1

2

Yes, your project will be a package.

A module is a collection of related code. Most non-trivial projects will be a collection of modules in a package (potentially with sub-packages).

6
  • So for example, if I write some code to work with my database (add and remove items for example) that would be a module inside a package (my project), isn't it? Nov 1, 2012 at 11:32
  • A module is a file, and a package is a folder, all code will be inside a module in one way or another, and if you have related code in more than one modules, you should put them in a package to show their relation. Nov 1, 2012 at 11:34
  • Ok, that is a good definition. Thank you. A last question. What about init.py files? I read that are used as a main script in packages and to define directories in Python so these will be easily imported but looking for examples in GitHub I found a lot of these files completly empty. Is there any reason? Nov 1, 2012 at 11:37
  • Sorry, I mean (underscore)(underscore)init(underscore)(underscore).py files. Sorry again for the new comment but I can't edit the previous one :S Nov 1, 2012 at 11:48
  • 1
    __init__.py files signify that the folder is a package, they don't need to contain anything, although they can contain code that is run when the package is imported. Nov 1, 2012 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.