How does IPython's magic %paste work?

前端 未结 6 2174
南笙
南笙 2020-12-07 15:31

I want to copy already indented Python code / whole functions and classes into IPython. Everytime I try the indentation is screwed up and I get following error message:

6条回答
  •  时光取名叫无心
    2020-12-07 16:00

    A clarification on the steps:

    • First, copy target lines into your clipboard.

    • Type into the iPython prompt:

      • If on Tkinter: enter %paste
      • Otherwise: enter %cpaste
    • Paste (Ctrl-V) and hit enter.

    • Then type -- and hit enter.

    For example:

    In [1]: %cpaste
    Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
    :for l in "Hello World":
    :    print l,
    :--
    H e l l o   W o r l d
    

提交回复
热议问题