Question

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"?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top