ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've got strange error with iteritems(). why is it so?
Code:
>>> class test:
def __init__(self,**marks):
self._marks = marks
def getMarks(self):
for key,value in self._marks.iteritems():
print (self._marks(key,value))
>>> t1=test(sub1=99,sub2=98)
>>> t1.getMarks()
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
t1.getMarks()
File "<pyshell#10>", line 5, in getMarks
for key,value in self._marks.iteritems():
AttributeError: 'dict' object has no attribute 'iteritems'
but when i did items(), it works well
Code:
__dict = {'sub1':99,'sub2':98}
>>> for key,val in __dict.items():
print(key,val)
sub2 98
sub1 99
Also i need to print the result in the same order as in the input i.e.
sub1 99
sub2 98.
how can I do it?
Last edited by jone kim; 05-03-2012 at 07:24 AM.
Reason: forget to add this query
I've got strange error with iteritems(). why is it so?
Code:
>>> class test:
def __init__(self,**marks):
self._marks = marks
def getMarks(self):
for key,value in self._marks.iteritems():
print (self._marks(key,value))
>>> t1=test(sub1=99,sub2=98)
>>> t1.getMarks()
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
t1.getMarks()
File "<pyshell#10>", line 5, in getMarks
for key,value in self._marks.iteritems():
AttributeError: 'dict' object has no attribute 'iteritems'
but when i did items(), it works well
Code:
__dict = {'sub1':99,'sub2':98}
>>> for key,val in __dict.items():
print(key,val)
sub2 98
sub1 99
Also i need to print the result in the same order as in the input i.e.
sub1 99 and after that
sub2 98.
how can I do it?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.