0

I am using Python 2.7 with Spyder

I am importing from a file (xxx.py) the value of some variables using a command like this:

from xxx import v1,v2,v3,v4

I can use the variables but Spyder shows me all the output from xxx.py (a series of print commands are run in the xxx.py file) prior to the output of the current program. Is there something that I can do to display only the output from the current file, running the code form xxx.py in "background"?

2 Answers 2

3

If there is code that you don't want executed when a module is imported, it should be protected as such:

if __name__ == "__main__":
   # code to run only when module is executed
   # as a script, not when imported.

Modules intended to be imported should probably not be writing to standard output.

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

1 Comment

To be completely clear, this change needs to be made in xxx.py and is basically a bug in that file.
0

Code on the toplevel of a module is executed at the first time the module is imported; so you have to move this code into functions, if you don't want it, to be executed.

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.