[BangPypers] How to run *.py scripts which interfaces with modules

Naresh Khalasi nkhalasi at vayana.in
Wed Jul 14 14:19:36 CEST 2010


Hi,

The root directory (where your package starts) should be added to PYTHONPATH
environment variable.
e.g. if your root directory is /home/<username>/projects/mailman
export PYTHONPATH=$PYTHONPATH:/home/<username>/projects/mailman

Once you do that you "cd" in the project directory and execute by saying
python Mailman/Bouncers/BouncerAPI.py <args>

or you can you use "python -m" if you want to run from a working directory
which is not your project directory.

Also ensure that each package directory contains "__init__.py" file so that
python can treat/identify it as a package directory.

- Naresh

On Wed, Jul 14, 2010 at 5:09 PM, स्वक्ष <vid at svaksha.com> wrote:

> Hi,
>
> I'd like to know how individual python web scripts of a package are
> run independently?
>
> For example:
> http://bazaar.launchpad.net/~mailman-coders/mailman/2.1/annotate/head:/Mailman/Bouncers/BouncerAPI.py
>
> The BouncerAPI.py program when its run, in turn calls another module
> syslog (Mailman/Logging/Syslog.py). How can I execute the program
> BouncerAPI.py independently for a unit test and avoid "ImportError: No
> module named Mailman.Logging.Syslog" errors ?
>
> Currently each *.py file links (calls?) other modules in different
> directories. i'd like to be able to give the PATH externally, else the
> *.py file throws an error when its run. Its possible to internally
> modify each file but that is tedious task for more than 2-3 files. So
> how do i give the PATH externally which will run a *.py file sans the
> module errors?
>
> TIA,
> --
> peace,
> vid || http://svaksha.com
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>


More information about the BangPypers mailing list