I have a .ipynb file and want to only import certain functions from it to another .ipynb file.
if I use:
if __name__ == "__main__":
would the script run what is under that if statement when I call:
%run file
For instance I have:
def someFuncToUseInOtherFile(df):
x = do some process
return x
def someFuncToUseInDifferentFile():
y = do some process
return y
#code not to run when script called from other file
if __name__ == "__main__":
df = load dataframe
x = ....
#other file
%run file
currently this runs the whole script but I just want to import the one function not both.
I have tried importing directly like a .py file, including using sys.path.append:
from file import someFuncToUseInOtherFile --> module not found error
import sys
sys.path.append(folder path)
from file import someFuncToUseInOtherFile --> module not found error
is there a way to get around this?
%rundoesn’t import a module. It runs a script.