I am new to PyCharm. I have been using IDLE for a long time.
It is very convenient to use Python objects after script execution in IDLE. Is there any way to use scr
*update
From your update, I think this SO question provides at least one perfect answer.
Let me write it here a little more step by step than the answer I linked.
import myscript
(without .py) (if you want a short name, use import myscript as m
main()
if you have an if __name__ == '__main__'
block)a
is available in myscript.a
myscript = reload(myscript)
*original
In PyCharm 3.0 you can do the following:
Is that what you are looking for? If not, please try them and let me know how that is different from what you want.
I found to previous answers from Piga-fetta, Games Brainiac and kobejohn useful, but not satisfying. So I here provide a third option:
Loading selected code into the console (my suggestion)
Use Shift + Alt + E to load the selected code or the line in which the cursor is placed into the console and immediately run it. This also have some disadvantages:
But in return we get a feature that is better than IDLE (in my opinion): Being able to run your code one selection at a time.
Read about it here.
Using breakpoints and Evaluate Expression (Alt-F8) (suggested by Piga-fetta)
This is very useful in big application where we need to debug at certain locations in the code, but not so useful for interactive coding. So this is not what we want.
Using Tools --> Run Python Console (suggested by Games Brainiac and kobejohn)
This is want we want, but is is a bit cumbersome, especially if the the module we want to run is not in the root directory of the project.
In addition to the suggestion I made on Ramkins's answer, you can run the file directly with the console by right clicking inside the file and selecting Run File in Console
.
Not mentioned above:
If you want to use a variable during execution, e.g. to when you set a breakpoint and then experiment with calling functions on objects in current scope, PyCharm has an 'Evaluate Expression (Alt-F8)' popup window.
In this window, you can call functions and see the output. Code completion also works. This window also has a "code fragment mode", I am just researching what it means - can you define temporary functions here?.
(I am using PyCharm 3.0.1 Community Edition)
You can simply use the Python Console inside both PyCharm 2 and PyCharm 3. And you can simply import since your project root is already added to your PYTHONPATH
:
So let me demonstrate through some screen shots:
console.py
file in root directoryconsole.py
fileAnd there, you have imported your variable successfully.
For anyone still having this problem: Go to the Run/Debug menu, choose Edit Configuration, check the box 'Show command line' this will enable you to enter parameters in the console at the >>> prompt and test your function.
To make this change apply to all your .py files (as this check box only applies to the current file you're working on) go to: Edit configuration, in the pop up you will see a menu tree on the left, select Defaults, then Python, then check the 'Show command line' box, this will make it the default setting whenever you open a .py file, (this feature should really be on by default!)