[IPython-user] help about own magic

Luc ORTEGA luc.ortega@grenoble.cnrs...
Fri Jan 4 18:02:28 CST 2008

Hi everybody,
I would like to do the following with an own magic command :
I have a function like "test(s1,f1,f2,s2='std')" and I want to type in 
the prompt:
 >>> test 'A' 45 67.8 'B'
or only >>> test 'A' 45 67.8
[Later, the best would be to type only at the end:
 >>> test A 45 67.8 B (where A and B could be defined definitively (as 
constant) A="A" B="B" )]
Probably, it is obvious but I tried to make a short test but without 
success and I checked also the mailing for the last 8 months.

I did:
def test(s1,f1,f2,s2='std'):
print 'String1: %s X float1: %f X float2: %f X string2: %s ' % (s1, f1, 
f2, s2)

import IPython.ipapi
ip1 = IPython.ipapi.get()
def dotest(self, arg1, arg2, arg3, arg4):
self.api.ex("test(%s , %f , %f , %s)" % (arg1,arg2,arg3,arg4))

ip1.expose_magic('Mtest', dotest)
In Ipython, I have:

In [3]: %Mtest 'A' 45 67.8 'B'
TypeError Traceback (most recent call last)

C:\Documents and Settings\Ortega\Mes documents\DEV\Reflux\<ipython 
console> in <module>()

C:\Python25\Lib\site-packages\IPython\iplib.py in ipmagic(self, arg_s)
946 else:
947 magic_args = self.var_expand(magic_args,1)
--> 948 return fn(magic_args)
950 def ipalias(self,arg_s):

TypeError: dotest() takes exactly 5 arguments (2 given)

Could you provie me any help ?
Thanks a lot and best wishes, Luc


/ /


CNRS - Institut NÉEL

Département Matière Condensée Matériaux et Fonctions

Bâtiment F, bureau F311

25 rue des martyrs, BP166

F38042 GRENOBLE Cedex 9 – FRANCE

Tél. : (+33) 4 7688 7801

Fax : (+33) 4 7688 1038

luc.ortega@grenoble.cnrs.fr <mailto:luc.ortega@grenoble.cnrs.fr>

/L’Institut Néel est une unité propre du CNRS conventionnée avec 
l’Université J. Fourier et à l’INP de Grenoble/

More information about the IPython-user mailing list