Running a module from the pycharm console(从 pycharm 控制台运行模块)
问题描述
我是 python 和 pycharm 的新手,如果可能的话,我想从 pycharm 控制台以与从 IDLE 相同的方式运行模块.
我们的想法是创建简单的函数并使用控制台实时"测试它们.
...你是如何在 pycharm 中做到这一点的?
使用 pycharm 运行 python 脚本非常简单,引用自 文档:
<块引用>使用临时运行/调试配置运行脚本 打开编辑器中所需的脚本,或在项目工具窗口中选择它.在上下文菜单中选择运行,或按 Ctrl+Shift+F10.所以这样做时,会即时创建临时运行/调试配置.
此外,pycharm 中还有一个Python 控制台":请参阅 文档一个>.
更新:这是一个例子.
假设您有一个名为 test_module.py 的 python 模块:
def a(*args, **kwargs):打印我是一个功能"def b(*args, **kwargs):打印我是函数 b"
然后,在 pycharm 的Python 控制台"中你可以这样做:
<预><代码>>>>从 test_module 导入 *>>>一个()我是一个功能>>>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 控制台运行模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 pycharm 控制台运行模块


基础教程推荐
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 筛选NumPy数组 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01