AttributeError

Denis McMahon denismfmcmahon at gmail.com
Thu Aug 13 05:15:20 EDT 2015


On Wed, 12 Aug 2015 16:46:32 -0700, Ltc Hotspot wrote:

> 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

If you read the text that I posted with the solution, it tells you what X 
and Y are. They are numbers that describe the positions of elements in 
your input data.

This absolute refusal by you to read any explanations that are posted are 
exactly why you will never be a good programmer. To become a good 
programmer you need to read and understand the explanations.

In the post with that code example, I wrote:

It also assumes that there is a timestamp of the form hh:mm:ss that 
always appears at the same word position X in each line in the file, and 
that the hours record always at position Y in the timestamp.

You have to replace X and Y in that line with numbers that represent the 
positions in the lists returned by the relevant split commands of the 
actual text elements that you want to extract.

-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list