Is this possible in Python?

Ron Garret rNOSPAMon at flownet.com
Mon Mar 13 12:56:30 EST 2006


In article <1142238871.199749.243470 at p10g2000cwp.googlegroups.com>,
 alainpoint at yahoo.fr wrote:

> Hi
> 
> I wonder if Python is capable of the following: define a function which
> returns its argument.
> I mean:
> def magic_function(arg):
>         ...... some magic code ...
> 
> that behaves the following way:
> 
> assert magic_function(3+4)=="3+4"
> assert magic_function([i for i in range(10)])=="i for i in range(10)]"
> 
> It is not trivial at all and might require some bytecode hacking that i
> am unable to do myself BUT you are the experts ;-)
> 
> Alain

You probably want to learn Lisp, where what you want to do is trivial:

(defmacro magic (arg) arg)

rg



More information about the Python-list mailing list