Imports

7stud bbxx789_05ss at yahoo.com
Tue Mar 20 20:44:09 EDT 2007


On Mar 20, 6:33 pm, "7stud" <bbxx789_0... at yahoo.com> wrote:
> On Mar 20, 12:51 pm, kyoso... at gmail.com wrote:
>
> > I typically just import sys and then do a
> > sys.path.append(directoryPath). This basically makes whatever modules
> > in that path available at run time. If you need a beginners reference
> > book, I recommend "Beginning Python" by Hetland. "Python Programming
> > for the Absolute Beginner" by Dawson was a lot of fun, but he doesn't
> > get into the internals of the language like Hetland does. Once you're
> > a snake charmer too, you can "graduate" to the "Programming Python"
> > book by Lutz.
>
> > Mike
>
> I can't access any modules using the sys.path.append() method.  Here
> is my directory structure:
>
> /
> ----Users
> ---------Me
> ------------2testing
> ------------------dir1
> ---------------------test1.py
> ---------------------programs_python
> -----------------------------testA.py
>
> testA.py:
> ------------------------
> def show(x):
>         print x
>
> if __name__ == "__main__":
>         show("hello")
> ------------------------
>
> test1.py:
> ------------------------
> import sys
>
> sys.path.append("/Users/Me/2testing/dir1/programs_python")
> testA.show("hello")
> ------------------------
>
> command:
> ~/2testing/dir1$ python test1.py
>
> output:
> Traceback (most recent call last):
>   File "test1.py", line 4, in ?
>     testA.show("hello")
> NameError: name 'testA' is not defined
>
> Any idea how to do that?

Hmmm...I got it to work like this:

test1.py:
---------
import sys
sys.path.append("/Users/Me/2testing/dir1/programs_python")

import testA
testA.show("hello")




More information about the Python-list mailing list