Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a module from the pycharm console

Tags:

I'm new to python and pycharm and I'd like to run a module from the pycharm console in the same way as you can from IDLE, if it's possible.

The idea is to create simple functions and test them "live" using the console.

...how do you do that in pycharm?

like image 232
user2443457 Avatar asked Jun 01 '13 15:06

user2443457


People also ask

How do I run a module in PyCharm?

Choose Run | Run from the main menu or press Alt+Shift+F10 , and then select the desired run/debug configuration.

How do I import a module into PyCharm console?

Go to File -> Settings (or Default Settings) -> Build, Execution, Deployment -> Console -> Python Console. Now I can import modules inside the source roots in the console!

How do I run a Python file from console in Python?

To run Python scripts with the python command, you need to open a command-line and type in the word python , or python3 if you have both versions, followed by the path to your script, just like this: $ python3 hello.py Hello World!

How do I run a specific file in PyCharm?

Alt + Shift + F10 and then select the script you want to run. After that Shift + F10 will run the last script that has been run.


1 Answers

Running python scripts using pycharm is pretty straightforward, quote from docs:

To run a script with a temporary run/debug configuration Open the desired script in the editor, or select it in the Project tool window. Choose Run on the context menu, or press Ctrl+Shift+F10. So doing, a temporary run/debug configuration is created on-the-fly.

Besides there is a "Python Console" available in pycharm: see documentation.

UPD: Here's an example.

Imagine you have a python module called test_module.py:

def a(*args, **kwargs):     print "I'm function a"  def b(*args, **kwargs):     print "I'm function b" 

Then, in pycharm's "Python Console" you can do this:

>>> from test_module import * >>> a() I'm function a >>> b() I'm function b 

If you need to execute a part of an existing code, you can use the Execute Selection in Console feature: select the code snippet -> right click -> "Execute Selection in Console".

like image 178
alecxe Avatar answered Nov 05 '22 09:11

alecxe