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-ID: 7190659300

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

Ausgedruckt am: 21.11.2024 um 19:11 Uhr

7010350221
Lösung 7010350221 17.05.2023 aktualisiert um 17:32:13 Uhr
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