Calling user defined functions from a different script..

V

venutaurus539

Hello all,
I have a situation where I need to call functions present in
a different script whose hierarchy is something like below:

C:\Pythonlib\uitl\script1.py {Place where my functions definitions are
present}

C:\Scripts\script2.py { Place where function calls are made}

In such a situation how can I import functions from
script1.py and use it in script2.py.


Please let me know if you need any further details.

Thank you,
Venu Madhav.
 
J

John Machin

Hello all,
          I have a situation where I need to call functions present in
a different script whose hierarchy is something like below:

C:\Pythonlib\uitl\script1.py {Place where my functions definitions are
present}

C:\Scripts\script2.py { Place where function calls are made}

           In such a situation how can I import functions from
script1.py and use it in script2.py.

http://docs.python.org/tutorial/modules.html#the-module-search-path
 
A

Aaron Brady

Hello all,
          I have a situation where I need to call functions present in
a different script whose hierarchy is something like below:

C:\Pythonlib\uitl\script1.py {Place where my functions definitions are
present}

C:\Scripts\script2.py { Place where function calls are made}

           In such a situation how can I import functions from
script1.py and use it in script2.py.

Please let me know if you need any further details.

Thank you,
Venu Madhav.

From what I understand, you just want a certain line in a certain
file. The line is the path to the directory you want to import from,
pythonlib\util. The file is {python_direcotry\}Lib\site-packages
\locals.pth.

Here's mine:

C:\Programs\Python25\Lib\site-packages>type locals.pth
/Documents and Settings/usr/My Documents/
/Documents and Settings/usr/Desktop/working/imptest/

If you want to import multiple directories, you need another file
which will be blank. The blank file goes in the directory you will be
importing. It is called '__init__.py'.

Mine:

Directory of C:\Documents and Settings\usr\My Documents\Lib

04/08/2008 03:35 PM 0 __init__.py

Then I can do:

C:\Programs\Python25>python
Python 2.5.4 (r254:67916, Dec 23 2008
Type "help", "copyright", "credits" o
I'm not sure about other versions than 2.5.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top