Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you organize Python modules? [closed]

Tags:

python

module

When it comes to organizing python modules, my Mac OS X system is a mess. I've packages lying around everywhere on my hdd and no particular system to organize them.

How do you keep everything manageable?

like image 651
ak. Avatar asked Oct 05 '08 10:10

ak.


People also ask

How do you organize Python modules?

Organize your modules into packages. Each package must contain a special __init__.py file. Your project should generally consist of one top-level package, usually containing sub-packages. That top-level package usually shares the name of your project, and exists as a directory in the root of your project's repository.

Where should I store my Python modules?

For the most part, modules are just Python scripts that are stored in your Lib or Lib/site-packages folder, or local to the script being run. That's it.

How should I organize my Python code?

Modules are files with “. py” extension containing Python code. They help to organise related functions, classes or any code block in the same file. It is considered as a best practice to split the large Python code blocks into modules containing up to 300–400 lines of code.


2 Answers

My advice:

  • Read Installing Python Modules.
  • Read Distributing Python Modules.
  • Start using easy_install from setuptools. Read the documentation for setuptools.
  • Always use virtualenv. My site-packages directory contains setuptools and virtualenv only.
  • Check out Ian Bicking's new project pyinstall.
  • Follow everything Ian Bicking is working on. It is always goodness.
  • When creating your own packages, use distutils/setuptools. Consider using paster create (see http://pythonpaste.org) to create your initial directory layout.
like image 140
codeape Avatar answered Sep 24 '22 19:09

codeape


In addition to PEP8 and easy_install, you should check out virtualenv. Virtualenv allows you to have multiple different python library trees. At work, we use virtualenv with a bootstrapping environment to quickly set up a development/production environment where we are all in sync w.r.t library versions etc. We generally coordinate library upgrades.

like image 40
I GIVE CRAP ANSWERS Avatar answered Sep 21 '22 19:09

I GIVE CRAP ANSWERS