Skip to content
This repository

paste command not working #211

Closed
MEQ opened this Issue December 04, 2010 · 9 comments

5 participants

MEQ Min RK Thomas Kluyver Matty G Zach Fogg
MEQ

I apologize if this is user error. I'm new to Python and even newer to IPython. :)

Windows XP, sp3.
Python 2.6
IPython 0.10.1 win32

If I understand correctly, the paste command doesn't need any parameters. It's supposed to pull the contents of the clipboard then paste and run it.

Clipboard contents:
print "my clipboard paste test"
--

Result:

In [43]: paste
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

C:\Dev\Python\ in ()

C:\Program Files\Python26\lib\site-packages\IPython\iplib.pyc in ipmagic(self, arg_s)
   1180         else:
   1181             magic_args = self.var_expand(magic_args,1)
-> 1182             return fn(magic_args)
   1183
   1184     def ipalias(self,arg_s):

C:\Program Files\Python26\lib\site-packages\IPython\Magic.pyc in magic_paste(self, parameter_s)
   3411             return
   3412
-> 3413         text = self.shell.hooks.clipboard_get()
   3414         block = self._strip_pasted_lines_for_code(text.splitlines())
   3415         self._execute_block(block, par)

C:\Program Files\Python26\lib\site-packages\IPython\hooks.pyc in __call__(self, *args, **kw)
    139             #print "prio",prio,"cmd",cmd #dbg

    140             try:
--> 141                 ret = cmd(*args, **kw)
    142                 return ret
    143             except ipapi.TryNext, exc:

C:\Program Files\Python26\lib\site-packages\IPython\hooks.pyc in clipboard_get(self)
    260     dispatcher = CommandChainDispatcher()
    261     for func in chain:
    262         dispatcher.add(func)
--> 263     text = dispatcher()
    264     return text

C:\Program Files\Python26\lib\site-packages\IPython\hooks.pyc in __call__(self, *args, **kw)
    139             #print "prio",prio,"cmd",cmd #dbg

    140             try:
--> 141                 ret = cmd(*args, **kw)
    142                 return ret
    143             except ipapi.TryNext, exc:

TypeError: tkinter_clipboard_get() takes no arguments (1 given)
Matty G

This also appears broken in Linux (Ubuntu)

In [5]: %paste
---------------------------------------------------------------------------
TryNext                                   Traceback (most recent call last)
/home/meawoppl/Dropbox/repos/git-repos/3scan-microscope/reconstruction/<ipython-input-5-771cb64cec93> in <module>()
----> 1 get_ipython().magic(u"paste")

/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s, next_input)
   1892                 self._magic_locals = sys._getframe(1).f_locals
   1893             with self.builtin_trap:
-> 1894                 result = fn(magic_args)
   1895             # Ensure we're not keeping object references around:

   1896             self._magic_locals = {}

/usr/local/lib/python2.7/dist-packages/IPython/frontend/terminal/interactiveshell.pyc in magic_paste(self, parameter_s)
    577             return
    578 
--> 579         text = self.shell.hooks.clipboard_get()
    580         block = self._strip_pasted_lines_for_code(text.splitlines())
    581 

/usr/local/lib/python2.7/dist-packages/IPython/core/hooks.pyc in __call__(self, *args, **kw)
    139                     kw = exc.kwargs
    140         # if no function will accept it, raise TryNext up to the caller

--> 141         raise TryNext
    142 
    143     def __str__(self):

TryNext: 

Thats all . . .

Min RK
Owner

See #880. On Linux, %paste depends of python-tk to get the clipboard, but the error message should make that clear.

Thomas Kluyver
Collaborator

I think the original (Windows) error reported here is different from what #880 is about.

In the Linux example posted here, it's failing to find any working clipboard implementation: #880 says we should have a more informative error message. The Windows example seems to actually be a bug with the call to the clipboard API, but maybe it has since been fixed.

Min RK
Owner

Ah, good point. Yes, I think the Windows Error has been fixed. I'll quickly test on Windows, and just close this if so, leaving the link to #880 which is the answer for @meawoppl.

Min RK
Owner

Indeed, %paste works on Windows. Closing this issue.

Min RK minrk closed this October 20, 2011
Zach Fogg
zfogg commented May 05, 2012

Seems to be broken in the same way for me too :(. Funny, it was just working yesterday.

I'm running Windows 7, zsh via Cygwin, Python 2.7, and ipython 0.12.1

In [4]: %paste
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
C:\Users\Zachary\<ipython-input-4-da94f22893b1> in <module>()
----> 1 get_ipython().magic(u'paste')

C:\Python27\lib\site-packages\IPython\core\interactiveshell.pyc in magic(self, arg_s, next_input)
  1983                 self._magic_locals = sys._getframe(1).f_locals
  1984             with self.builtin_trap:
-> 1985                 result = fn(magic_args)
  1986             # Ensure we're not keeping object references around:

  1987             self._magic_locals = {}

C:\Python27\lib\site-packages\IPython\frontend\terminal\interactiveshell.pyc in magic_paste(self, param
eter_s)
    633             return
    634         try:
--> 635             text = self.shell.hooks.clipboard_get()
    636             block = strip_email_quotes(text.splitlines())
    637         except TryNext as clipboard_exc:

C:\Python27\lib\site-packages\IPython\core\hooks.pyc in __call__(self, *args, **kw)
    133             #print "prio",prio,"cmd",cmd #dbg

    134             try:
--> 135                 return cmd(*args, **kw)
    136             except TryNext, exc:
    137                 if exc.args or exc.kwargs:

C:\Python27\lib\site-packages\IPython\core\hooks.pyc in clipboard_get(self)
    225     for func in chain:
    226         dispatcher.add(func)
--> 227     text = dispatcher()
    228     return text

C:\Python27\lib\site-packages\IPython\core\hooks.pyc in __call__(self, *args, **kw)
    133             #print "prio",prio,"cmd",cmd #dbg

    134             try:
--> 135                 return cmd(*args, **kw)
    136             except TryNext, exc:
    137                 if exc.args or exc.kwargs:

TypeError: tkinter_clipboard_get() takes no arguments (1 given)
Thomas Kluyver takluyver reopened this May 06, 2012
Thomas Kluyver
Collaborator

Thanks, @zachfogg . I see the issue: if one function in the command chain fails, it attempts to pass the arguments from the TryNext error to the next function. In this case, the Windows clipboard function fails, which raises TryNext with an error message in the arguments, so it tries to pass the error message to the Tkinter clipboard function.

I'll work on a proper fix, in the meantime, installing pywin32 should avoid the problem. That's probably why we couldn't replicate it.

Thomas Kluyver
Collaborator

If anyone on Windows without pywin32 wants to test, PR #1703 should fix this.

Zach Fogg
zfogg commented May 06, 2012

Thanks @takluyver, installing pywin32 solved my problem!

Thomas Kluyver takluyver closed this in cdd3c85 May 09, 2012
Damián Avila damianavila referenced this issue from a commit July 30, 2013
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.