Listing variables

vsoler vicente.soler at gmail.com
Sun Oct 25 19:03:59 CET 2009


On Oct 25, 5:07 pm, Tim Chase <python.l... at tim.thechases.com> wrote:
> >> 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

Thank you Tim, everything is clear now.

Vicente Soler



More information about the Python-list mailing list