AttributeError

Ltc Hotspot ltc.hotspot at gmail.com
Thu Aug 13 01:46:32 CEST 2015


>> How do I define the file name in order to remove the traceback?
>>
> At this point I think I'll just let you figure that out for yourself...
>
> --
> https://mail.python.org/mailman/listinfo/python-list

MRAB,

How do I define X?
-------------------------------------------------------------------------------------
Traceback reads:

     10 f  = open(filename,'r')
     11 for l in f:
---> 12      h = int(l.split()[X].split(':')[Y])
     13      c[h] = c[h] + 1
     14 f.close()

NameError: name 'X' is not defined
-------------------------------------------------------------------------------------
Revised code reads:
handle = """From stephen.marquard at uct.ac.za Sat Jan  5 09:14:16 2008
>From louis at media.berkeley.edu Fri Jan  4 18:10:48 2008
""".split("\n") # Snippet file data: mbox-short.txt

filename = raw_input("Enter file:")
if len(filename) < 1 : filename = "mbox-short.txt"


c = [0 for i in range(24)]
f  = open(filename,'r')
for l in f:
     h = int(l.split()[X].split(':')[Y])
     c[h] = c[h] + 1
f.close()
for i in range(24):
     print '{:02d} {}'.format(i, c[i])


Regards,
Hal


More information about the Python-list mailing list