If you are working on a code (sample.py) that uses functions of another file (simpleops.py) in the same directory, you can simply call "import simpleops" and then use the functions in that file as "simpleops.() " as shown in the below example.
Example:
Your current program (sample.py):
#!/usr/bin/env python
import simpleops
print simpleops.sum(5,3)
print simpleops.mult(5,3)
If the another file is in different directory compared to your current file, then you should first import its directory path and then import the file like: "sys.path.insert(0,FILEPATH) import simpleops " as shown in the below example. Note that the value '0' in sys.path.insert means it first searches the modules in the current directory first from the program has been called.
Example:
Your current program(sample.py):
#!/usr/bin/env python
import sys
sys.path.insert(0, FILEPATH)
import simpleops
print simpleops.sum(5,3)
print simpleops.mult(5,3)
For example lets say, your sample code (simpleops.py) looks like this:
#!/usr/bin/env python
def mult(a,b):
return(a*b)
def sum(a,b):
return(a+b)
Example:
Your current program (sample.py)
#!/usr/bin/env python
import simpleops
print simpleops.sum(5,3)
print simpleops.mult(5,3)
If the another file is in different directory compared to your current file, then you should first import its directory path and then import the file like: "sys.path.insert(0,
Example:
Your current program
#!/usr/bin/env python
import sys
sys.path.insert(0, FILEPATH
import simpleops
print simpleops.sum(5,3)
print simpleops.mult(5,3)
For example lets say, your sample code (simpleops.py) looks like this:
#!/usr/bin/env python
def mult(a,b):
return(a*b)
def sum(a,b):
return(a+b)