@ayende You ought to try Mercurial. in reply to ayende 2 weeks ago
27
Dec

Django: ValueError: too many values to unpack

I came across this error this morning on a Django project that I’m working on in my spare time. I was trying to add some custom permissions to one of the models, as outlined in the documentation, only to have it choke with this message when I ran manage.py syncdb.

A bit of Googling got me to this site, but unfortunately it’s in Polish. Never mind, Google Translate managed to give me enough information. Turns out that I had missed out a comma that I didn’t think was necessary:

class Meta:
  permissions = (
    ("can_drive", "Can drive"),
    ("can_vote", "Can vote in elections"),
    ("can_drink", "Can drink alcohol"),   # <== This comma is important!
  )

Hmmm, I always thought that last comma in Python was only an optional extra in case you decided to add an extra item to the end of a tuple and forgot to add it in to the previous line. Seems it does have some obscure but significant semantic importance after all.

3 comments:

  • 24 Jan 2009
    08:35

    Thanks for posting this. It saved me a lot of time. Cheers!

  • Luke Jernejcic
    3 Aug 2009
    04:06

    I just wanted to add that I got this error because I was missing the comma on my PAGE_TEMPLATES tuple. FYI.

  • dd
    17 Oct 2009
    03:50

    create lists with defined number of elements
    list = [] * 100
    enjoy

Comments on this entry are now closed.