Syed Naqi Syed Naqi - 1 month ago 15
Python Question

how can I access functions from another program into my new program

I'm trying to write a program that is related to another program, so how can I access the individual functions from my previous program and work with them as required, I know you are suppose to import that program but what to do after that.
The program that I import how can I use functions from it.

Answer

It would be better if you write code. I assume your 1st code is code1.py and you want to use fun1 from it in code2.py. Put them in same directory . . .

Use:

import code1
code1.fun1()

Or

from code1 import *
fun1()

Note: 2nd method is not recommended.