StringIO readline() bug??
piet at cs.uu.nl
piet at cs.uu.nl
Fri Oct 13 08:08:32 EDT 2000
More information about the Python-list mailing list
Fri Oct 13 08:08:32 EDT 2000
- Previous message (by thread): StringIO readline() bug??
- Next message (by thread): Most Effective Way to Build Up a Histogram of Words?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
>>>>> Chris Arai <chris at araidesign.com> (CA) writes: CA> Hello, CA> I'm new to python, but I think I have found a bug in StringIO. In any CA> case I'm having a problem. CA> readline() on a StringIO object crashes with an attribute error: >>>> fstr.readline() CA> Traceback (innermost last): CA> File "<pyshell#37>", line 1, in ? CA> fstr.readline() CA> File "/usr/lib/python1.6/StringIO.py", line 83, in readline CA> i = string.find(self.buf, '\n', self.pos) CA> File "/usr/lib/python1.6/string.py", line 171, in find CA> return _apply(s.find, args) CA> AttributeError: find CA> The history is that: CA> 1 . I opened a text file >>>> file=open("legalfilename",'r') CA> 2. then I scoop that file's text into a StringIO object: >>>> fstr=StringIO(file.readlines()) The documentation says that you have to pass it a STRING. However, you are passing it a string LIST. Apparently the constructor is not testing it at this moment. >>>> fstr.readline() #crashes, with the above message The readline starts to find in what it supposes to be a string, but which is actually a list, and a list doesn't have a find method. So change the constructor call above to: fstr=StringIO(file.read()) -- Piet van Oostrum <piet at cs.uu.nl> URL: http://www.cs.uu.nl/~piet [PGP] Private email: P.van.Oostrum at hccnet.nl
- Previous message (by thread): StringIO readline() bug??
- Next message (by thread): Most Effective Way to Build Up a Histogram of Words?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list