The "Python Console" is a separate environment from the one you run code in when you press "Run...".
First of all: Use the excellent debugging facilities provided by PyCharm to step through your code and see whether things work as they should in situ.
If that for some reason doesn't do it for you:
You can from <yourfile> import *
in the console, if running pure python. That will get you your variables. If you do import <yourfile>
, the script will be run, but your variables will only be available as <yourfile>.<var>
. Of course, anything you have under if __name__ == '__main__'
won't be executed.
If this won't do, I refer you to https://stackoverflow.com/a/437857/3745323:
with open("yourfile.py") as f:
code = compile(f.read(), "yourfile.py", 'exec')
exec(code, global_vars, local_vars)
You can definen that as a function in a separate file and import it. Alternatively, just type it into the interpreter.
If you have IPython installed, recent PyCharm editions default to using it in the console. In this case you can use the %run
magic to run your script as if it was typed in line-by-line into the interpreter.
In[2]: %run yourfile