Question1: How type of argument should I use for dict, i.e.,user argument or list argument.
Read captured traceback: TypeError Traceback (most recent call last) C:\Users\vm\Desktop\apps\docs\Python\assignment_9_4_26.py in <module>() 1 fname = raw_input("Enter file name: ") 2 handle = open (fname, 'r') ----> 3 count = dict.keys() 4 for line in handle: 5 if line.startswith("From: "): TypeError: descriptor 'keys' of 'dict' object needs an argument In [99]: Question2: Are all the loop failures resolved in the revised code? Revised code is available at https://gist.github.com/ltc-hotspot/00fa77ca9b40c0a77170 Regards, Hal On Thu, Aug 6, 2015 at 4:20 PM, Alan Gauld <alan.ga...@btinternet.com> wrote: > On 07/08/15 00:11, Ltc Hotspot wrote: > >> Questions(1):Why does print line, prints blank space; and, (2) print >> address prints a single email address: >> > > See my previous emails. > You are not storing your addresses so address only holds the last address > in the file. > line is at the end of the file so is empty., > > In [72]: print count >> {'gopal.ramasammyc...@gmail.com <mailto:gopal.ramasammyc...@gmail.com>': >> 1, 'lo...@media.berkeley.edu <mailto:lo...@media.berkeley.edu>': 3, >> 'cwen@iupui. >> edu': 5, 'antra...@caret.cam.ac.uk <mailto:antra...@caret.cam.ac.uk>': >> 1, 'rjl...@iupui.edu <mailto:rjl...@iupui.edu>': 2, 'gsil...@umich.ed >> u': 3, 'david.horw...@uct.ac.za <mailto:david.horw...@uct.ac.za>': 4, ' >> wagne...@iupui.edu <mailto:wagne...@iupui.edu>': 1, 'zq...@umich.edu >> <mailto:zq...@umich.edu>': >> 4, 'stephen.marqu...@uct.ac.za <mailto:stephen.marqu...@uct.ac.za>': 2, >> 'r...@media.berkeley.edu <mailto:r...@media.berkeley.edu>': 1} >> >> Question(3): why did the elements print count('keys') and print >> count('items') fail? >> > > Because, as shown above, count is a dictionary. > So items and keys are methods not strings to be passed > to a non-existent count() function. > > So you need, for example: > > print count.keys() > > Traceback (most recent call last) >> <ipython-input-76-35c8707b256e> in <module>() >> ----> 1 print count('items') >> >> TypeError: 'dict' object is not callable >> >> > Which is what the error is also telling you. > You cannot call - ie use () - with a dictionary like count. > > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor