When to put my modules

Bob van der Poel bvdpoel at kootenay.com
Tue Dec 30 11:45:35 EST 2003



Yermat wrote:
> Hi,
> 
> "Bob van der Poel" <bvdpoel at kootenay.com> a écrit dans le message de
> news:3ff0e744_1 at dns.sd54.bc.ca
> 
>>I'm working on a moderately sized application and I'm planning on
>>having a fair number of modules. The only question in my mind is:
>>where do I put the modules ... and how do I let python know about
>>them?
> 
> 
> see http://www.python.org/doc/current/tut/node8.html especially the 6.1.1
> 

Okay...so I just need to add paths to the sys.path variable. Seems 
simple enough. Thanks.

>>I could put them with the rest  of the python lib, but I'm not really
>>presumtious to do that.
> 
> 
> Not that good...
> 
> 
>>I can keep them all in the current directory, but that forces the user
>>to chd to a certain location all the time.
>>
>>Best, I think, is to put them in a program specific location. My
>>program needs some other data files, etc. so I'm thinking that I can
>>just put the python stuff in /usr/local/lib/MYPROGRAM/modules.
> 
> 
> Not that good too. You may want to re-use your module later in another
> program...
> 

Well, probably not. The modules I'm talking about here are pretty 
specific to my program.

>>Okay, but what about when I'm just working on them? In this case I'd
>>like them to be in my current working dir.
>>
>>Is there a magic line I need to add to the top of the main module to
>>set the path up?
>>
>>Apologies if this is covered in a document...but I can't see to find
>>anything. Maybe this is a faq?
> 
> 
> What I'm doing is something like this :
> All my module are in a directory such as /home/loic/MyPython/.
> I set the PYTHONPATH to that directory.
> I've got for example a module rtf in /home/loic/MyPython/rtf/, another one
> Heredis in /home/loic/MyPython/Heredis and my program is in
> /home/loic/MyPython/Heredis2Gedcom for example.
> In that way, I don't mix my module with standard one. Every program can
> access all non program specific module.
> 
> For other tips, look at sys.path too.
> 
> Hope it help !
> Yermat

Yes, it does help. Just to clearify, the program I'm working on will be 
distributed to other users. So, putting the modules in a 
my-personal-python-stuff directory isn't really an option. They most 
likely need to go in the main python tree (which, again, I don't like), 
or in a program specific directory. Setting PYTHONPATH is an option, but 
I don't like to force a user to set an env variable just to run my 
program. Yes, I could turn my prog into a shell script which sets the 
variable, and then runs the *real* program, but I always find that 
method to be a bit convoluted.

> 

-- 
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: bvdpoel at kootenay.com
WWW:   http://www.kootenay.com/~bvdpoel




More information about the Python-list mailing list