Re: [Tutor] python import problem
The other way would be to add each folder to your PYTHONPATH It works for me now: import sys import os.path sys.path.append(os.path.join(sys.path[0] ,translate)) That isn't using PYTHONPATH its updaing sys.path which is slightly different.. This way you need to do that for every program usi9ng your folder but if you modify the PYTHONPATH environment variable you only need to do it once and Python will add it to sys.path for you. HTH, Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python import problem
the folders modules and translate are in the same level, so if I want to import factory.py into myfile.py, how can I do? You need to make your folders into packages. Its fairly simple, you basically create an init.py file But its worth reading about packages in the docs Come back here ifv you have any questions after that. The other way would be to add each folder to your PYTHONPATH HTH, Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python import problem
if I want to import factory.py into myfile.py, how can I do? You need to make your folders into packages. Its fairly simple, you basically create an init.py file But its worth reading about packages in the docs Come back here ifv you have any questions after that. The other way would be to add each folder to your PYTHONPATH the rules for importing modules in packages is going to change over the next few releases... read up on those changes starting from here: http://docs.python.org/dev/whatsnew/pep-328.html the simplest solution, as alan's described, is to put all directories that have your Python modules in the PYTHONPATH environment variable. if you are on a Unix-based system, just set this variable in your shell. if you are on Win32, right-mouse My Computer - System Properties - Advanced - Environment Variables - Edit (User or System variables) - Ok. cheers, -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Core Python Programming, Prentice Hall, (c)2007,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python import problem
បានសរសេរ Alan Gauld: Hi Alan, the folders modules and translate are in the same level, so if I want to import factory.py into myfile.py, how can I do? You need to make your folders into packages. Its fairly simple, you basically create an init.py file But its worth reading about packages in the docs Come back here ifv you have any questions after that. Sure, I can do it if I move translate folder into modules folder then create an empty init.py file. But I want another way, and PYTHONPATH is your right suggestion The other way would be to add each folder to your PYTHONPATH It works for me now: mport sys import os.path sys.path.append(os.path.join(sys.path[0] ,translate)) Cheers, da ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor