-1

How the from in python know the PATH of the directory that all module are exists?

For example

Under

   /data_py/Python/modulespy

I have all the modules as:

Df.py
Tr.py
Sw.py

So how the following from syntax in python know to access the /data_py/Python/modulespy folder and read all modules there

fromPymoduleeimport*
maihabunash
  • 1,632
  • 9
  • 34
  • 60

1 Answers1

1
>>> import sys
>>> print sys.path
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']

This way you can find it out, which all path python will look for the modules

Update as per the comment:

You can insert your path into the list. Index 0 has the first priority.

sys.path.insert(0, '/data-py/modules')
Suku
  • 3,820
  • 1
  • 21
  • 23
  • 1
    but - if for example I want to build a new module and under other folder as /data-py/modules , then how to import the new module? – maihabunash Aug 12 '15 at 08:16
  • This gives a good overview: http://stackoverflow.com/questions/3144089/expand-python-search-path-to-other-source – lemonhead Aug 12 '15 at 08:20