Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't paste multiple lines in latest iPython

I am using the latest ipython 5.1 and python 3, but have trouble in directly pasting multiple lines to the command line. I am working on CentOs.

Can somebody try pasting the Duck class on the wiki (https://en.wikipedia.org/wiki/Duck_typing) and see whether you can get any error:

class Duck:
    def quack(self):
        print("Quaaaaaack!")
    def feathers(self):
        print("The duck has white and gray feathers.")

All these are properly indented and can be pasted into my .py file and run fine. But when I paste it to iPython, I always receive this error:

In [8]: class Duck:
   ...:         def quack(self):
   ...:                 print("Quaaaaaack!")
   ...:             def feathers(self):
  File "<ipython-input-8-aca228a732db>", line 4
    def feathers(self):
                       ^
IndentationError: unindent does not match any outer indentation level

EDITTED:

Both my %paste and %cpaste don't work. I have installed the Tinker library, as seen below:

[abigail@localhost my_env]$ rpm -q tkinter
tkinter-2.7.5-39.el7_2.x86_64

But %paste always displays an error:

In [10]: %paste
ERROR:root:Getting text from the clipboard on this platform requires Tkinter.

%cpaste doesn't work either, it doesn't print anything to the screen:

In [8]: %cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:--

In [9]: 

EDITTED:

[abigail@localhost my_env]$ sudo yum install python3-tk
[sudo] password for abigail: 
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.supremebytes.com
 * epel: mirrors.kernel.org
 * extras: mirror.supremebytes.com
 * ius: mirrors.kernel.org
 * nux-dextop: li.nux.ro
 * rpmfusion-free-updates: mirror.web-ster.com
 * rpmfusion-nonfree-updates: mirror.web-ster.com
 * updates: mirror.supremebytes.com
No package python3-tk available.
Error: Nothing to do

python3-tk not available on CentOS 7?

like image 714
user697911 Avatar asked Nov 22 '16 22:11

user697911


2 Answers

For using %paste you need to install python3-tk. And I guess you misunderstood how %cpaste works. Run it, paste your code, press Enter, enter --, press Enter again.

like image 137
Sergey Gornostaev Avatar answered Sep 18 '22 16:09

Sergey Gornostaev


If you use %cpaste, you have to type %cpaste, then ctrl+shift+v to paste, then type -- and then enter to exit the pasted text screen. Any stdout should appear after this.

Example:

In [2]: %cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:class Duck:
    def quack(self):
        print("Quaaaaaack!")
    def feathers(self):
        print("The duck has white and gray feathers.")::::
:--

In [3]: d = Duck()

In [4]: d.quack()
Quaaaaaack!
like image 27
Blairg23 Avatar answered Sep 22 '22 16:09

Blairg23