passing keyword arguments that are themselfs python keywords

Fredrik Lundh fredrik at
Mon Feb 5 14:57:09 EST 2001

Stefan Seefeld wrote:
> I'm trying to write a python function that can take keywords such as 'class'.
> Is that possible ?


the usual workaround is to use a trailing underscore,
and strip it away inside your function:

    entity('div', text, class_='header')

or you could force your users to use ** syntax and
an ordinary dictionary:

    entity('div', text, **{'class': 'header'})

Cheers /F

More information about the Python-list mailing list