why * is not like unquote (scheme)

Oren Tirosh oren-py-l at hishome.net
Thu Mar 20 06:50:43 EST 2003


On Thu, Mar 20, 2003 at 01:26:07PM +0200, Amir Hadar wrote:
> Hi
> 
> I'me tring to create a factory function that create a class as follow:
> 
> def CreatePreviewFrame(*addins):
>     class tmp(cPreviewFrame,*addins):
>         pass
>     return tmp
> 
> I checked a simpler case:
> (1,2,*(3,4))
> and this is also syntax error.
> 
> but I can path parameters to a function as follow:
> 
> def f(a,b):
>      print a,b
> 
> l = ("a","b")
> f(*l)
> 
> So why doesn't it work in all cases?

The * is specific to calls. It does not apply to other places in the 
systax where a comma-separated list is acceptable.

You can do what you want using the exec statement or by directly 
creating the class object with new.classobj() instead of using the
class statement.

    Oren






More information about the Python-list mailing list