Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > a question on the new dict() keyword argument syntax

Reply
Thread Tools

a question on the new dict() keyword argument syntax

 
 
Oktay Safak
Guest
Posts: n/a
 
      08-01-2003
Hi,

Is there an equivalent keyword argument syntax for these cases:

d1 = {1:"one"}

d2 = {"1":"one"}

these don't work, of course:

>>> a = dict(1 = "one")

SyntaxError: keyword can't be an expression

>>> a = dict("1" = "one")

SyntaxError: keyword can't be an expression

Just curious...
 
Reply With Quote
 
 
 
 
Raymond Hettinger
Guest
Posts: n/a
 
      08-01-2003
"Oktay Safak" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi,
>
> Is there an equivalent keyword argument syntax for these cases:
>
> d1 = {1:"one"}
>
> d2 = {"1":"one"}
>
> these don't work, of course:
>
> >>> a = dict(1 = "one")

> SyntaxError: keyword can't be an expression
>
> >>> a = dict("1" = "one")

> SyntaxError: keyword can't be an expression


As you discovered, there is no equivalent. The new
syntax is limited to strings that are valid identifiers
(variable names).


Raymond Hettinger




 
Reply With Quote
 
 
 
 
Oktay Safak
Guest
Posts: n/a
 
      08-02-2003
> > Hi,
> >
> > Is there an equivalent keyword argument syntax for these cases:
> >
> > d1 = {1:"one"}
> >
> > d2 = {"1":"one"}
> >
> > these don't work, of course:
> >
> > >>> a = dict(1 = "one")

> > SyntaxError: keyword can't be an expression
> >
> > >>> a = dict("1" = "one")

> > SyntaxError: keyword can't be an expression

>
> As you discovered, there is no equivalent. The new
> syntax is limited to strings that are valid identifiers
> (variable names).
>
>
> Raymond Hettinger


Thanks
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Special keyword argument lambda syntax Beni Cherniavsky Python 1 03-14-2009 05:48 PM
Keyword argument 'from'; invalid syntax Kai Kuehne Python 4 07-26-2007 05:50 AM
RE: keyword checker - keyword.kwlist Hamilton, William Python 4 05-13-2007 06:31 AM
keyword checker - keyword.kwlist tom@finland.com Python 6 05-10-2007 04:53 PM
Again, Rite explanation needed (keyword args and new hash syntax) gabriele renzi Ruby 12 11-19-2003 02:10 PM



Advertisments