Python Script Referencing
I have 2 python files (.py) named file1 and file2.
Question: I want to import file 2 into 1 and run file 1
- file 1 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 2
# ::::::::::::::::::::::::::::::::::::::::::::::::::::
# file B has the following codes:
# x and y are from file 1
a = x + y
c = a + z
print (c)
# I have tried to use the following:
# into file 1
from fileB import*
# and also from fileA import* #
# into file B so I can use some variables in file 1.
# But I get errors as name x and y are not defined for file2
Please also mark the comments that contributed to the solution of the article
Content-ID: 7190659300
Url: https://rootdb.com/en/python-script-referencing-7190659300.html
Printed on: February 23, 2025 at 07:02 o'clock
1 Comment

Sample:
Now all clear
?
Just read the instructions 😋
Regards
# first.py
def foo(): print("foo")
def bar(): print("bar")
# second.py
import first
first.foo() # prints "foo"
first.bar() # prints "bar"
Just read the instructions 😋
Regards