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 控制台运行模块
基础教程推荐
- 尝试制作WhatsApp机器人 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
