Imports
Steve Holden
steve at holdenweb.com
Tue Mar 20 21:12:28 EDT 2007
7stud wrote:
> 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")
>
That's how it's s'posed to work. You still have to explicitly import the
modules you want - the sys.path just tells Python where to look for them.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Recent Ramblings http://holdenweb.blogspot.com
More information about the Python-list
mailing list