| | |
Where to place modules?
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
I always tend to stick the main program one directory above all the other modules. My directory tree will look something like this:
And so on. Obviously, "gameboard.py", etc. are the modules. I've wrapped them in a subdirectory-module. To use them, I import them in gork.py thus:
Hope this helps.
Python Syntax (Toggle Plain Text)
Gork/ gork.py README ... images/ title.tga player1.tga player2.tga ... modules/ __init__.py gameboard.py globals.py tga32.py widgets.py ...
Python Syntax (Toggle Plain Text)
from modules.globals import * import modules.widgets ...
You can put them in a directory in the PYTHONPATH, so Python can find it (be careful with that one):
Or better, add your own module directory (let's say MyModules) to PYTHONPATH. You have to add this all your programs that import one of your modules then:
python Syntax (Toggle Plain Text)
# show PYTHONPATH import sys print sys.path
python Syntax (Toggle Plain Text)
import sys sys.path.append(r'C:\Python25\MyModules')
Last edited by Ene Uran; Jan 6th, 2008 at 2:20 pm. Reason: []
drink her pretty
•
•
Join Date: Jul 2006
Posts: 608
Reputation:
Solved Threads: 150
sys.path is just the search path that the system uses to look up files whose full pathname is not given.
That is, a statement like
import mymodule1
will search the directories in sys.path for mymodule1.py.
So by itself, your statement would not create a directory. Rather, it would tell Python to add that directory to the list of paths to search.
Try this:
That should make a directory.
BTW, "/media/disk/..." -- your copy of Python isn't on CD-ROM or some other read-only media, is it?
Jeff
That is, a statement like
import mymodule1
will search the directories in sys.path for mymodule1.py.
So by itself, your statement would not create a directory. Rather, it would tell Python to add that directory to the list of paths to search.
Try this:
Python Syntax (Toggle Plain Text)
import os os.mkdir("/media/disk/usr/lib/python2.5/MyModules")
That should make a directory.
BTW, "/media/disk/..." -- your copy of Python isn't on CD-ROM or some other read-only media, is it?
Jeff
![]() |
Similar Threads
- Icons from SQL to ToolStripMenuItem ? (C#)
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- Classes (VB.NET)
- Distribution of code between modules (IT Professionals' Lounge)
- another newbie with alot of redhat and apache server Q'S (Linux Servers and Apache)
- VB and Excel Programming (VB.NET)
- Possibly overheating? (Cases, Fans and Power Supplies)
- c lang doubts (C)
- can't start computer (Windows 95 / 98 / Me)
Other Threads in the Python Forum
- Previous Thread: Python-mysql for checking table exist or not
- Next Thread: Euler's Number with 100 Digit Precision (Python)
| Thread Tools | Search this Thread |
abrupt ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog decimals dictionaries dictionary directory drive dynamic error examples excel exe file float format function gnu graphics gui heads homework http ideas import input java launcher leftmouse line linux list lists logging loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyqt python random recursion schedule scrolledtext sqlite statistics stdout string strings sudokusolver sum table terminal text thread threading time tkinter tlapse tricks tuple tutorial twoup ubuntu unicode update urllib urllib2 variable ventrilo wikipedia windows write wxpython xlib






