AttributeError Problem
MRAB
python at mrabarnett.plus.com
Tue Apr 23 21:17:48 EDT 2013
On 24/04/2013 01:28, animemaiden wrote:
> On Tuesday, April 23, 2013 8:02:08 PM UTC-4, Skip Montanaro wrote:
>> > numberOfVertices = int(infile.readline().decode()) # Read the first line from the file
>>
>> > AttributeError: 'str' object has no attribute 'readline'
>>
>> ...
>>
>> > infile = filedialog.askopenfilename()
>>
>>
>>
>> This is just returning a filename. You need to open it to get a file
>>
>> object. For example:
>>
>>
>>
>> infile = filedialog.askopenfilename()
>>
>> fd = open(infile)
>>
>> ...
>>
>> numberOfVertices = int(fd.readline().decode())
>>
>>
>>
>> Skip
> Thanks, but now I have this error AttributeError: 'str' object has no attribute 'decode'
>
You already have a string (the line) that you've read from the file, so
what are you trying to 'decode' anyway? Just remove that erroneous
method call.
More information about the Python-list
mailing list