从pycharm控制台运行模块 [英] Running a module from the pycharm console

查看:1553
本文介绍了从pycharm控制台运行模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python和pycharm的新手,我想从pycharm控制台运行一个模块,就像IDLE一样,如果可能的话。



这个想法是创建简单的函数,并使用控制台测试他们活。



...在pycharm中如何做?

解决方案

使用pycharm运行python脚本非常简单,引用文档


要运行具有临时运行/调试配置在编辑器中打开
所需的脚本,或在项目工具窗口中选择它。
在上下文菜单中选择运行,或按Ctrl + Shift + F10。所以
在做,一个临时运行/调试配置是即时创建的。


控制台:请参阅文档



UPD:
下面是一个例子。



想象一下,你有一个python模块 test_module.py

  def a(* args,** kwargs):
printI 'm function a

def b(* args,** kwargs):
printI'm function b
 >>>> from test_module import * 
>>> a()
我的函数a
>>> b()
我是函数b






如果您需要执行现有代码的一部分,则可以使用在控制台中执行选择功能:选择代码段 - >右键 - >在控制台中执行选择。


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?

解决方案

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

这篇关于从pycharm控制台运行模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆