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?
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With