dict tuple update
Roy Smith
roy at panix.com
Mon May 5 21:04:06 EDT 2003
Tertius <tertiusc at netscape.net> wrote:
> # I need to change all None values in the tuple values to "" (empty
> # string) Errors happen when trying to update the tuple. I presume its #
> # because a dict value is referenced. I tried copy and deepcopy but no #
> # luck.
> # t[j] = ""
> # TypeError: object doesn't support item assignment
The problem is that tuples are immutable. It's got nothing to do with
the fact that they're stored in a dict. You'll get the same result with
an isolated tuple:
>>> t = ("title1", "", None, None, None)
>>> t[2] = ''
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: object doesn't support item assignment
If you want to be able to update the values, you'll need to store them
in a list, not a tuple.
More information about the Python-list
mailing list