1

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

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
Sign up to request clarification or add additional context in comments.

4 Comments

if file 1 is in the same directory your method works, but its not :/
second method does not work, i get 'cannot import name 'server_ip''
Did you write the path correctly, without the filename (only where the directory is)?
Ah, ive inlcluded the file name thats why it didnt work. Thankyou Everybody!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.