type = "instance" instead of "dict"
Kent Johnson
kent at kentsjohnson.com
Mon Feb 27 15:16:05 EST 2006
Cruella DeVille wrote:
> I'm trying to implement a bookmark-url program, which accepts user
> input and puts the strings in a dictionary. Somehow I'm not able to
> iterate myDictionary of type Dict{}
>
> When I write print type(myDictionary) I get that the type is
> "instance", which makes no sense to me. What does that mean?
Maybe you have an instance of UserDict instead of a built-in dict?
>>> type({})
<type 'dict'>
>>> from UserDict import UserDict
>>> type(UserDict())
<type 'instance'>
UserDict.UserDict is not iterable, though you can still use
for k in myDictionary.keys()
There is also UserDict.IterableUserDict which does support iteration.
I don't think there is much reason to use UserDict in modern Python as
dict can be subclassed.
Kent
More information about the Python-list
mailing list