如何让 PyC​​harm 中的 Python 控制台访问脚本的变量空间? [英] How to give the Python console in PyCharm access to the variable space of a script?

查看:21
本文介绍了如何让 PyC​​harm 中的 Python 控制台访问脚本的变量空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法,让 PyC​​harm 中的 Python 控制台(可从 Tools -> Run Python Console... 访问)由我目前正在使用的脚本定义.

例如,假设我的脚本(PyCharm 项目的一部分)包含以下行

aa = 4

然后我想直接进入控制台并操作刚刚由脚本定义的变量,例如

<预><代码>>>>一个*28

我找不到这样做的方法,以及相关的问题

I'm looking for a way to give the Python console in PyCharm (available from Tools -> Run Python Console...) access to the variables that were defined by a script that I'm currently working with.

For instance, say that my script (part of a PyCharm project) contains the line

aa = 4

I then want to go straight to the console and manipulate the variable that was just defined by the script, e.g.

>>> aa*2
8

I can't find a way to do this, and the related question Is there a Variable Explorer for PyCharm doesn't help me: the accepted answer there seems to imply that the console in fact should have access to the variable space of the current workspace/script, but that isn't true in my case.

(As a side note: The above was possible in the only other IDE that I've tried other than PyCharm: PyScripter. It is also how I'm used to work in MATLAB.)

解决方案

This answer works in the Pycharm Python console. Another option is to run in debug mode. You can click on the "Show Python Prompt" icon in the bottom left corner of the debug console to open a prompt to access the variable space (circled red in screenshot below Pycharm 2017.3.3 Community edition)

这篇关于如何让 PyC​​harm 中的 Python 控制台访问脚本的变量空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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