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
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 7190659300
Url: https://administrator.de/en/python-script-referencing-7190659300.html
Ausgedruckt am: 22.12.2024 um 11:12 Uhr
1 Kommentar
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