PDA

View Full Version : [SOLVED] python, trouble with modules



TheLions
November 27th, 2009, 07:47 PM
I wrote one python program which consists of 10 functions. All functions and "main" function are in single file. I would like to chop that single file in several files, that each funtion is in separate file.

e.g.

#file.py - current state of my prog
def f1():

bla..

return something

def f2():

bla..

return something

def f3():

bla..

return something

a=f1()
b=f2()
c=f3()
#end of file.py

i would like to split it like this:

#f1.py
def f1():

bla..

return something
#end f1.py

#f2.py
def f2():

bla..

return something
#end f2.py

#f3.py
def f3():

bla..

return something
#end f3.py

#main.py
"""import f1, f2, f3"""

a=f1()
b=f2()
c=f3()
#end of main.py

How to import f1, f2 and f3 into "main.py" and how to call functions f1, f2 and f3 in "main.py"?

-grubby
November 27th, 2009, 07:50 PM
http://docs.python.org/tutorial/modules.html

TheLions
November 27th, 2009, 08:02 PM
http://docs.python.org/tutorial/modules.html

thanks, I dont know how I missed from X import Y in tutorial...