python - 如何在bpython中剪切和粘贴?
问题描述
如果可能的话,我想直接在 shell 会话中剪切和粘贴。我在 .py 文件中有一个简单的 with 块:
with open('t1_equip.json') as json_file:
data = json.load(json_file)
# Print the type of data variable
print("Type:", type(data))
这将很容易地剪切和粘贴到解释器中。但是,如果我尝试直接在 bpython 会话本身中剪切和粘贴,则会引发错误:
>>> with open('t1_equip.json') as json_file:
... ... data = json.load(json_file)
File "<bpython-input-57>", line 2
... data = json.load(json_file)
^
IndentationError: expected an indented block
>>> ... # Print the type of data variable
Ellipsis
>>> ... print("Type:", type(data))
File "<input>", line 1
... print("Type:", type(data))
^
SyntaxError: invalid syntax
我觉得必须有一个简单的工作流程改变,我只需敲几下键就可以做到这一点。必须不断地按向上箭头重新插入可以做到这一点,但我们可以为整个最后一个块做类似 %hist 或类似的事情吗?我怎样才能做到这一点?我将 zsh 与 oh-my-zsh 和 powerlevel10k 一起使用。
解决方案
不要使用python
命令。使用ipython
. 您可能需要通过pip install ipython
. 然后使用魔法命令,%paste
. 这将轻松复制引号块。
pip install ipython #Install
ipython # Opens ipython prompt
%paste
推荐阅读
- android - 是否仅为公共属性创建了支持属性?
- jstl - 我试图在 jstl 的帮助下使用 sql 但遇到异常
- php - 对加密的 PHP 对象进行排序
- ios - 无法从 Spring Boot 向 FCM 和远程用户发送推送通知?
- powershell - 正则表达式替换引号中的字符串路径
- python - python tkinter 没有在框架内创建另一个框架
- math - 算术表达式和大步语义
- vba - 如何使用 for 循环 vba 更改对象的名称?
- c - C 程序在 Apple Silicon macOS 上收到“killed 9”,但在 Intel 上很好
- javascript - Firestore - 从“collectionName/{id}”之类的引用中获取数据并遍历结果列表