Thanks for your responses. I guess the foo(**{'x-y':3}) is ugly but will do the trick <br><br>Cheers,<br>Khoa <br><br><div><span class="gmail_quote">On 1/5/06, <b class="gmail_sendername">Mike C. Fletcher</b> <<a href="mailto:mcfletch@rogers.com">
mcfletch@rogers.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Christian Tismer wrote:<br><br>>Khoa Nguyen wrote:
<br>><br>><br>>>I would like to pass some keyword with special character to a<br>>>foo(**kwargs) function, but it doesn't work<br>>><br>>>def foo(**kwargs):<br>>> print kwargs<br>>>
<br>>><br>>>This doesn't work:<br>>><br>>>foo(a-special-keyword=5)<br>>><br>>>How do I tell Python to treat '-' as a normal character but not part of<br>>>an expression?<br>>>
<br>>><br>><br>>By changing the parser :-)<br>><br>><br>Oh, you py-py guys, always thinking you have to re-implement Python ;)<br><br>>Keywords are limited to obey Python syntax.<br>><br>><br>Sure, but you can do something like this:
<br><br> >>> def x( **named ):<br>... print named<br>...<br> >>> x( **{'some-var-with- weird chars': True } )<br>{'some-var-with- weird chars': True}<br><br>That is, for the OP (who is unlikely to rewrite the parser), the
<br>solution could be as simple as treating the keyword as a piece of data<br>and applying it to the function.<br><br>Have fun,<br>Mike<br><br>--<br>________________________________________________<br> Mike C. Fletcher<br>
Designer, VR Plumber, Coder<br> <a href="http://www.vrplumber.com">http://www.vrplumber.com</a><br> <a href="http://blog.vrplumber.com">http://blog.vrplumber.com</a><br><br></blockquote></div><br>