+ 1

python importing a variable from another file without its functions

how do i import a variable in a different python file without importing its functions eg:= script1.py print("something") integer = 123 script2.py import script1 print(script1.integer) if i run script 2 i get something 123

23rd Feb 2022, 12:32 PM
Alviz #1216
Alviz #1216 - avatar
3 Answers
+ 5
Alviz #1216 , if you wanted to do so, you can import the variables from an other file. you can use the 2 attached files, which have comments about the procedure. i am not sure how to test it in sololearn, but in a regular ide environment it runs properly, if both files are stored in the same folder. this file holds the variables: https://code.sololearn.com/ceq5OR6wlZ2i/?ref=app this file has to be executed: https://code.sololearn.com/cCsl0l067Nid/?ref=app
23rd Feb 2022, 3:13 PM
Lothar
Lothar - avatar
+ 1
hey lothar i ran your code as you said but if you add a print statement before or after the code it will be displayed as well thanks for the answer please upvote my Question
24th Feb 2022, 2:35 PM
Alviz #1216
Alviz #1216 - avatar
0
from script1 import integer
23rd Feb 2022, 12:33 PM
Slick
Slick - avatar