Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

python - Running a module from the pycharm console

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...