rahuljain
Goto Top

Python Script Referencing

I have 2 python files (.py) named file1 and file2.

  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)
Question: I want to import file 2 into 1 and run file 1

# 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

Content-Key: 7190659300

Url: https://administrator.de/contentid/7190659300

Printed on: June 6, 2023 at 20:06 o'clock

Mitglied: 7010350221
Solution 7010350221 May 17, 2023 updated at 15:32:13 (UTC)
Goto Top
Sample:
# first.py
def foo(): print("foo")
def bar(): print("bar")

# second.py
import first

first.foo()    # prints "foo"
first.bar()    # prints "bar"
Now all clear face-wink ?

Just read the instructions ­čśő

Regards