I want to store some data and allocate some variables for it. This variable should be accessible from another python file.
FILE 1
server_ip ="BLAH"
pswd ="BLEH"
FILE 2
server = // server_ip of file 1
password = /pswd of file 1
1 Answer 1
Depending where is file1.py. If it's in the same directory, use
import file1
server = file1.server_ip
password = file1.pswd
If it isn't in the same directory, try:
import sys
sys.path.append(r"whatever\the\path\to\file1\is")
import file1
server = file1.server_ip
password = file1.pswd
answered Jun 11, 2017 at 13:18
user6597761
Sign up to request clarification or add additional context in comments.
4 Comments
user7625226
if file 1 is in the same directory your method works, but its not :/
user7625226
second method does not work, i get 'cannot import name 'server_ip''
user7625226
Ah, ive inlcluded the file name thats why it didnt work. Thankyou Everybody!
lang-py