[Tutor] readline() problem

hcohen2 hcohen2 at comcast.net
Wed Feb 11 17:28:50 EST 2004


Ron Alvarado wrote:

>Here's what I'm getting when I try readline(). What an I doing wrong?
>
>  
>
>>>>data = open('bData.csv', 'r')
>>>>num = True
>>>>while num != "":
>>>>        
>>>>
> data = data.readline()
> print data
>  
>
When you openned the file, data was the file handle which you have 
confused it with a string value of the same name.  Since data types are 
dynamic in Python your file handle value is lost.

try

str_data = data.readline()
print str_data

both that line and the print should be to the right of the 'while ...'

> 
>Part number Description Item Cost 1104 1105 1118
>
>
>Traceback (most recent call last):
>  File "<pyshell#7>", line 2, in -toplevel-
>    data = data.readline()
>AttributeError: 'str' object has no attribute 'readline'
>  
>
>
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>  
>





More information about the Tutor mailing list