mix up between numbers and strings

Aahz Maruch aahz at panix.com
Tue Sep 5 19:08:11 EDT 2000


In article <x%et5.130$me.274476 at nnrp5.proxad.net>,
Jad Courbage <jad at altern.org> wrote:
>
>I wrote a program to extract data from a file (with help of
>narray=file.readlines()).
>The problem is that it seems that the interpreter "thinks" that narray
>is a string array although the file it is extracted from is a number
>data file. Therefore, I can't manipulate my data as numbers.

You need to use the int() function to convert strings to numbers.  If
you're not certain that the data is convertable, wrap the int() in a
try/except ValueError block.
-- 
                      --- Aahz (Copyright 2000 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

Goodbye dinner for Netcom shell, Thurs 9/7, 7:30pm, Mountain View, CA
e-mail me for details



More information about the Python-list mailing list