Listing variables

Tim Chase python.list at tim.thechases.com
Sun Oct 25 12:07:26 EDT 2009


>> tim at rubbish:~/tmp$ rm test.py test.pyc
>> tim at rubbish:~/tmp$ python2.5
>>  >>> import test
>>  >>> dir(test)
>> ['__builtins__', '__doc__', '__file__', '__name__', '__path__']
>>  >>> test.__file__
>> '/usr/lib/python2.5/test/__init__.pyc'
>>
>> because there's apparently a module named "test" in the standard
>> distribution that gets found instead.
> 
> You were right. When I renamed my test.py file into test77.py it
> worked perfectly well. Thank you.
> 
> Is there a way to know which test.py it was importing?

well, as my simple code showed, you can check test.__file__ or
test.__path__ if you're curious.  Python just searches through 
your $PYTHONPATH which you can determine at runtime via sys.path

-tkc





More information about the Python-list mailing list