Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I come from a PHP background so I'm used to everything being in one place. I want to install a python program (Zine)so that I can hack on it. The instructions I've found install it to the system in multiple folders. I do not want to edit files that are installed in Linux system directories.

What is the python way to layout the directory on the filesystem for a web program that under active development?

would it be:

/web/htdocs/python/modules/app.py

or

/web/python/modules/app.py
/web/htdocs/

or

/web/python/modules/app.py
/web/python/htdocs/
share|improve this question
    
Take a look at virtualenv. If you want/need to experiment with packages that should replace your system packages, you can easily create a sandbox to experiment and/or reproduce your deployment environment. –  9000 Jul 3 '11 at 17:44
    
What do you use to run Python code? It's typical nowadays to run a Python-based web server that runs your code and hide it behind a 'normal' web server, usually via FastCGI. This way, you don't even need to give the webserver account any access to your code/data, since your Python server runs under a different user. Or do you use mod_python? –  9000 Jul 3 '11 at 17:50
    
I will be using mod_wsgi. I want to create a self contained python app (including htdocs) so I can keep it versioned in git, which also helps with deployment across my live, test and dev servers. –  Supermighty Jul 3 '11 at 19:03
add comment

1 Answer

Python uses directories to form packages of modules. You then import the module (or what you need from a module) so it can be used in the file you are currently working in.

If the file's path is sound\effects\echo.py, you would import it like this:

import sound.effects.echo
share|improve this answer
    
So just put everything in my web root and import from there? htdocs/python/package –  Supermighty Jul 3 '11 at 13:41
1  
They just need to be somewhere that Python can find it. Module Search Path. –  unholysampler Jul 3 '11 at 14:36
1  
Don't put your packages to htdocs/ unless you want everyone to observe your source code (or, worse, configs and data files). Put the code somewhere where your server can access it and put that dir on PYTHONPATH of your Python interpreter. –  9000 Jul 3 '11 at 17:46
    
Sounds like there is no best practice for file location with web applications. –  Supermighty Jul 3 '11 at 18:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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