0

I'm writing an automated internet speed testing program and I've setup a secondary script, config.py, to make it simpler for the user to edit the configuration.

The program can send tweets when the internet speed results falls below a certain point and I want to give the users the ability to edit the tweet. However the user wil likely want to include the results in the tweet which will be defined in the script within which config.py is called.

How can I use the variables from the main script in config.py?

Edit: Should've mentioned the variables in the main script are also in functions.

2 Answers 2

1

You can do from main_script import variable if the variables are not encapsulated into functions.

Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately they are in functions.
0

__main__ provides the namespace of the initial starting script:

# config.py
import __main__
print __main__.some_script_variable

Or you could use an extra module, e.g. cfgdata.py, which you import from main script and config.py.

Comments

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.