reading txt file

MRAB python at mrabarnett.plus.com
Thu May 31 12:51:21 EDT 2012


On 31/05/2012 16:02, Ahmed, Shakir wrote:
> HI:
> I am trying to read a txt file and dump the columns in an access database table. But getting problem:
>
>>>>  Unhandled exception while debugging...
> Traceback (most recent call last):
>    File "C:\WindDuration\Reading_test.py", line 14, in<module>
>      my_length_1 = nmAddrList[1]
> IndexError: list index out of range
>
> Getting error when it is reading to second line.
>
> The txt file is attached here and I need only 2,8,11,14,15 columns to dump in the table.
>
>
> Any help is highly appreciated.
>
Most of the lines end with "\n" followed by "\r\n", so when you read
those lines you get a line of data followed by a blank line.

The simplest solution is just to skip blank lines.



More information about the Python-list mailing list