I'm looking for a way to give the Python console in PyCharm (available from Tools
-> Run Python Console...
) access to the variables that were defined by a script that I'm currently working with.
For instance, say that my script (part of a PyCharm project) contains the line
aa = 4
I then want to go straight to the console and manipulate the variable that was just defined by the script, e.g.
>>> aa*2
8
I can't find a way to do this, and the related question Is there a Variable Explorer for PyCharm doesn't help me: the accepted answer there seems to imply that the console in fact should have access to the variable space of the current workspace/script, but that isn't true in my case.
(As a side note: The above was possible in the only other IDE that I've tried other than PyCharm: PyScripter. It is also how I'm used to work in MATLAB.)
You can assign a shortcut to open Python console: press Ctrl+Alt+S , navigate to Keymap, specify a shortcut for Main menu | Tools | Python or Debug Console. The main reason for using the Python console within PyCharm is to benefit from the main IDE features, such as code completion, code analysis, and quick fixes.
PyCharm allows you to inspect variables in a dedicated dialog. This is useful when you need to keep track of some variable (or the object whose reference it holds) and at the same time be able to navigate between frames and threads. Right-click a variable on the Variables tab and select Inspect.
Go to the Edit Configurations as pointed by other answers. Click edit the configuration templates in the panel. Edit environment variables there.
The way to do this, if you don't have ipython:
-i nameoffile.py
, where nameoffile.py
is the name of the file you want to have available to you.Next, go to Run > Run 'nameoffile.py'
or SHIFT+F10
This will create a Python interpreter, which will already have your file's variables available. Its the "normal" way to do the %run
magic command.
You can also do this from the command line, python -i somefile.py
will cause the Python interpreter to load with the file somefile.py
already loaded.
PyCharm can make use of an IPython console if you have it installed, what this means is that you can use the IPython magic functions such as %run my_filename.py
to run Python code.
The only way I know of doing what you want is to manually run the Python code in the console yourself, using the %run
command, which will run the file and also give you access to any variables, functions, etc that have been defined inside your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With