0

如果可能的话,我想直接在 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 一起使用。

4

1 回答 1

0

不要使用python命令。使用ipython. 您可能需要通过pip install ipython. 然后使用魔法命令,%paste. 这将轻松复制引号块。

pip install ipython  #Install

ipython # Opens ipython prompt
%paste
于 2021-03-28T16:04:26.800 回答