views:

27

answers:

1

i've a small user defined function in python, say fib(n), how do i use that in other programs or modules? def fib(n):

should i use import or is there any other feature?

Also i'm learning python in eclipse IDE, it wont support

print "any string"

but i'm forced to use like, print("string")

in python manual online, its given its cross platform and same syntax, but why like above?

+2  A: 

You use import to include the function in other programs. Just say import mymodule where the code is located in file mymodule.py. Then say mymodule.fib to use the function.

To answer your second question: The syntax print "any string" is acceptable in Python 2, but is no longer allowed in Python 3.

Justin Ethier
ok fine, i'm using python 2.6.5, so it wont support....
abhilashm86
previously i was trying to importing function itself!! now i get them working, thanks......
abhilashm86