Changes between Version 13 and Version 14 of NewbieMistakes


Ignore:
Timestamp:
Dec 23, 2005, 11:45:00 AM (18 years ago)
Author:
scum
Comment:

added detail on how python treats (x) and (x,). Added bracket hint.

Legend:

Unmodified
Added
Removed
Modified
  • NewbieMistakes

    v13 v14  
    107107}}}
    108108
    109 It's a standard python error - you are just missing a comma in the list_display assignement like this:
     109You are just missing a comma in the list_display assignement like this:
    110110
    111111{{{
     
    119119}}}
    120120
    121 Since a tuple is expected but a string provided, the code will merrily iterate over the characters of the string instead of the tuple elements - and that's where the single-char attribute names come from.
     121Remember, in python:
     122{{{
     123#!python
     124>>> a = (1) ## This causes problems
     1251
     126>>> a = (1,) ## These are fine.
     127(1,)
     128>>> a = [1]
     129[1]
     130>>> a = [1,]
     131[1]
     132}}}
     133
     134Since a tuple is expected but a string provided, the code will merrily iterate over the characters of the string instead of the tuple elements - and that's where the single-char attribute names come from. If the commas are consistently causing you problems, try using brackets [] instead of parentheses.
Back to Top