i am newbie in python and i was running program and maybe it is written in python2.X which is provided by my friend,
but it was not running because i was getting error of dict object has no attribute viewkeys
originally when i have ran the script error was as below:
Traceback (most recent call last):
File "test.py", line 236, in <module>
for key in (Data_Pe.keys() | Data.viewkeys()):
AttributeError: 'dict' object has no attribute 'viewkeys'
in it Data_pe
and Data
both are dict
object.
I have tried to find on stackoverflow but i have not found any question related to this so i have asked and answered it myself, i have found the answer on the python documentation which was as below
dict
Fixes dictionary iteration methods.
dict.iteritems()
is converted todict.items()
,dict.iterkeys()
todict.keys()
, anddict.itervalues()
todict.values()
. Similarly,dict.viewitems()
,dict.viewkeys()
anddict.viewvalues()
are converted respectively todict.items()
,dict.keys()
anddict.values()
. It also wraps existing usages of dict.items(), dict.keys(), and dict.values() in a call to list.
so in short in python3.X version it is changed from :
dict.viewkeys()
to dict.keys()