【问题标题】:How to cut and paste in bpython?如何在bpython中剪切和粘贴?
【发布时间】:2021-06-24 18:53:06
【问题描述】:

如果可能的话,我想直接在 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 interpreter django-shell bpython


    【解决方案1】:

    不要使用python 命令。使用ipython。您可能需要通过pip install ipython 安装它。然后使用魔术命令%paste。这将很容易复制引号块。

    pip install ipython  #Install
    
    ipython # Opens ipython prompt
    %paste
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-08
      • 2014-01-19
      • 1970-01-01
      • 2018-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-31
      相关资源
      最近更新 更多