[IPython-user] paste from clipboard as numpy array

Pavlo Shchelokovskyy shchelokovskyy@gmail....
Wed Jan 27 08:32:18 CST 2010


Hi all users and developers of IPython,
I'm actively using ipython, and I simply love it, but there is one
problem I am experiencing.

I would like to have possibility to copy some data as tab-separated
multi-line text and paste it directly into ipython as (2D) numpy
array. Although PyReadline's intro says it can "Smart paste for
convenient use with ipython. Converting tab separated data to python
list or numpy array", I never worked for me that way.

On Windows (XP, Python 2.6.4, IPython 0.10) any attempt to use it
results in error (foo = "1\t2\t3"):

In [1]: %paste foo
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

l:\devel\<ipython console> in <module>()

C:\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:\Python26\lib\site-packages\IPython\Magic.pyc in magic_paste(self,
parameter_s)
  3397             return
  3398
-> 3399         text = self.shell.hooks.clipboard_get()
  3400         block = self._strip_pasted_lines_for_code(text.splitlines())
  3401         self._execute_block(block, par)

C:\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:\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:\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)

This must be a bug since on Linux (Fedora8, Python 2.5.1, IPython
0.10) I am able to do that and result looks much like advertised (just
text converted to with no conversion - list of lines, with tabs not
stripped etc), but still this need some processing to put it in numpy
array, especially if clipboard is multi-line.

So, is it indeed currently possible to easy paste a tab-separated
block of decimal characters into ipython directly as numpy array? If
yes then how can I do it?

Your help is very appreciated,
Pavlo Shchelokvoskyy.


More information about the IPython-user mailing list