Python : Some Help

greggpb

Expert Member
Joined
Apr 22, 2005
Messages
1,818
Reaction score
0
Location
Cape Town
Hi Guys I have been using Python for a while now doing scripts and moving files around.. I recently started to acces databases and create buisness objects...
this is the first time I am programing in an inturperated language

what I am struggling with is :

Is there a stadnard way to to set out python modules and directory structure for shared modules and how woul I do it.

Most of the help on the web is related to getting other people modules to work.. and since I am self teaching I would apprieciate it if anyone in the know could drop me a line..

Many thanks
Gregg
 
I'm not 100% sure what you're asking, but here is a common project layout that I've seen in open source projects (assume the project name is "proj"):

proj/ - The project root as well as your version control root.
proj/setup.py - distutils/setuptools/distrubute setup script.
proj/{README,TODO,DEPENDENCIES,WHATEVER} - Other informational files.
proj/bin/ - Contains executables. Often (in Python projects, specifically) these are just simple Python scripts along the lines of
Code:
import proj
proj.main()
proj/doc/ - Contains your project's documentation.
proj/etc/ - (Optional) Contains configuration files. Sometimes called "config" instead.
proj/lib/ - (Optional) Contains third-party libraries.
proj/share/ - (Optional) Contains data files used by your project.
proj/src/ - All source code goes under this dir.
proj/src/proj/ - The project Python module's root. This directory's name is the one you use in your import statement.
proj/src/proj/__init__.py - File needed to have Python recognise the directory as an importable module.
proj/src/proj/db/ - An example sub-module. from proj import db. Add more as necessary.
proj/src/proj/db/__init__.py - Diretories of sub-modules need these too, even if they're empty.

The proj/src/ directory is the one that goes in your PYTHONPATH environmental variable, so that Python can find proj/src/proj when doing import proj.

I've also seen many deviations from this structure and, after a few years of Python dev work, haven't found an official "standard" for package layout.

Does this answer your question?
 
I'm not 100% sure what you're asking, but here is a common project layout that I've seen in open source projects (assume the project name is "proj"):

proj/ - The project root as well as your version control root.
proj/setup.py - distutils/setuptools/distrubute setup script.
proj/{README,TODO,DEPENDENCIES,WHATEVER} - Other informational files.
proj/bin/ - Contains executables. Often (in Python projects, specifically) these are just simple Python scripts along the lines of
Code:
import proj
proj.main()
proj/doc/ - Contains your project's documentation.
proj/etc/ - (Optional) Contains configuration files. Sometimes called "config" instead.
proj/lib/ - (Optional) Contains third-party libraries.
proj/share/ - (Optional) Contains data files used by your project.
proj/src/ - All source code goes under this dir.
proj/src/proj/ - The project Python module's root. This directory's name is the one you use in your import statement.
proj/src/proj/__init__.py - File needed to have Python recognise the directory as an importable module.
proj/src/proj/db/ - An example sub-module. from proj import db. Add more as necessary.
proj/src/proj/db/__init__.py - Diretories of sub-modules need these too, even if they're empty.

The proj/src/ directory is the one that goes in your PYTHONPATH environmental variable, so that Python can find proj/src/proj when doing import proj.

I've also seen many deviations from this structure and, after a few years of Python dev work, haven't found an official "standard" for package layout.

Does this answer your question?


Spot on..

the "
proj/src/proj/ - The project Python module's root. This directory's name is the one you use in your import statement.
proj/src/proj/__init__.py - File needed to have Python recognise the directory as an importable module.
proj/src/proj/db/ - An example sub-module. from proj import db. Add more as necessary.
proj/src/proj/db/__init__.py - Diretories of sub-modules need these too, even if they're empty."

was what I was looking for ..

THank you very much
 
I'm not sure what environment you're working in but being aware of the PYTHONPATH environmental variable's function should make things easier to understand.

I would also definitely recommend looking into using the python util virtualenv.
 
Top
Sign up to the MyBroadband newsletter
X