I’m confused. I think this is going to be a simple error, but I can’t find what I’m doing wrong. I’m running python 2.4.4. I’ve written my first python script consisting of multiple files. I’ve read python looks in the current working directory, as well as all the usual paths for user-added modules. I’ve confirmed this by looking at sys.path:
$ python
Python 2.4.4 (#1, Jan 8 2013, 09:29:21)
[GCC 4.7.2 20120921 (Red Hat 4.7.2-2)] on linux3
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['', '/usr/local/lib/python24.zip', '/usr/local/lib/python2.4', '/usr/local/lib/python2.4/plat-linux3', '/usr/local/lib/python2.4/lib-tk', '/usr/local/lib/python2.4/lib-dynload', '/usr/local/lib/python2.4/site-packages']
>>>
The first entry, ”, represents look in the current working directory, yet it does not seem to be doing so. Here is the contents of my mult file python program. Note, everything is in the same directory:
$ ls
cherwellTicket.py dsutils.py emailMessage.py
$
Here is the contents of dsutils.py. This module contains various static methods I want to use in other classes:
#!/usr/bin/python
import getpass
import socket
class DSUtils:
# (I didn't paste the rest)
And here is the contents of cherwellTicket.py. Note, this is in the same directory:
#!/usr/bin/python
import DSUtils
class CherwellTicket:
def __init():
pass
Yet, when python trys to execute cherwellTicket.py, heres what happens:
$ python cherwellTicket.py
Traceback (most recent call last):
File "cherwellTicket.py", line 3, in ?
import DSUtils
ImportError: No module named DSUtils
$
Both files are in the same directory, so why is the cherwellTicket script now able to import the dsutils class?
DSUtilsis different thandsutils. I think you might want:The module is the name of the file (sans
.pyextension). Python doesn’t look at the classes within a module until the module is being imported.Alternatively,