Python Script Referencing or Calling
Question:
I have 2 python files (.py) named fileA and fileB.
# file A has the following codes:
import Pandas as pd
x = input (x)
z = input (y)
y = x + z
if y == 8:
fileB()
# Call or run file B
# ::::::::::::::::::::::::::::::::::::::::::::::::::::
# file B has the following codes:
# x and y are from file A
a = x + y
c = a + z
print (c)
Question: I want to import file B into A and run file A
# I have tried to use the following:
# into file A
from fileB import*
# and also from fileA import* #
# into file B so I can use some variables in file A.
# But I get errors as name x and y are not defined for fileB
Answers:
If you create a function in file B that does the maths it schould work:
def funB(x, z):
a = x + y
c = a + z
return c
then you can import that funcion in file A like:
from fileB import funB
if ...:
print(funB(x, y))
I have 2 python files (.py) named fileA and fileB.
# file A has the following codes:
import Pandas as pd
x = input (x)
z = input (y)
y = x + z
if y == 8:
fileB()
# Call or run file B
# ::::::::::::::::::::::::::::::::::::::::::::::::::::
# file B has the following codes:
# x and y are from file A
a = x + y
c = a + z
print (c)
Question: I want to import file B into A and run file A
# I have tried to use the following:
# into file A
from fileB import*
# and also from fileA import* #
# into file B so I can use some variables in file A.
# But I get errors as name x and y are not defined for fileB
If you create a function in file B that does the maths it schould work:
def funB(x, z):
a = x + y
c = a + z
return c
then you can import that funcion in file A like:
from fileB import funB
if ...:
print(funB(x, y))