On Mon, May 18, 2009 at 5:24 PM, Karen Tracey <[email protected]> wrote:

> On Mon, May 18, 2009 at 6:53 PM, Mohan Parthasarathy 
> <[email protected]>wrote:
>
>> Hi,
>>
>> class CategoryAdmin(admin.ModelAdmin):
>>         prepopulated_fields = {'slug' : ('title', )}
>>
>> Why does the format require a comma after "title'. It is still a valid
>> tuple without a comma, right ?
>
>
> No, it's a string.  Single-element tuples require a trailing comma (more
> than they require the parens, actually).  See:
> http://docs.python.org/tutorial/datastructures.html#tuples-and-sequences
>
>
>> Without that, I keep getting errors.
>>
>
> You're actually lucky there.  Often these sneak by without an immediate
> error, and at some point way later some code iterates over your "tuple",
> producing, since strings are iterable too, the unexpected sequence 't', 'i',
> 't', 'l', 'e'.  That sort of thing often leads to much harder to find
> bugs....or maybe that's the error you encountered?
>
>
>>
>> Sorry, If this was a dumb question. I am parallely doing python and
>> django. Atleast creating a dictionary in python did not require a comma for
>> the tuple
>>
>
> Not dumb...it's a Python gotcha that routinely trips up newcomers to the
> language.  I'd recheck that your dictionary-creation code is actually
> creating what you want.  It may look like it's working but lead to problems
> down the line if you are missing trailing commas on what are supposed to be
> single-element tuples.
>

Thanks a lot. Though the dictionary was created, I did not bother to check
whether it was a string or a tuple.

Thanks again!
mohan


>
> Karen
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to