471,616 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,616 software developers and data experts.

cStringIO.StringIO has no write method?

This program:

import sys
import traceback
import cStringIO

a = 1.0
b = 0.0
try:
c=a/b
except:
f = cStringIO.StringIO('')
ei = sys.exc_info()
traceback.print_exception(ei[0],ei[1],ei[2],file=f)

raises this exception:

Traceback (most recent call last):
File "C:/Documents and Settings/gandalf/test.py", line 12, in ?
traceback.print_exception(ei[0],ei[1],ei[2],file=f)
File "C:\Python24\Lib\traceback.py", line 124, in print_exception
_print(file, 'Traceback (most recent call last):')
File "C:\Python24\Lib\traceback.py", line 13, in _print
file.write(str+terminator)
AttributeError: 'cStringIO.StringI' object has no attribute 'write'

What is 'cStringIO.StringI' anyway? Shouldn't it be 'cStringIO.StringIO'?

Laszlo

Jul 25 '06 #1
3 6297
Laszlo Nagy wrote:
This program:

import sys
import traceback
import cStringIO

a = 1.0
b = 0.0
try:
c=a/b
except:
f = cStringIO.StringIO('')
ei = sys.exc_info()
traceback.print_exception(ei[0],ei[1],ei[2],file=f)

raises this exception:

Traceback (most recent call last):
File "C:/Documents and Settings/gandalf/test.py", line 12, in ?
traceback.print_exception(ei[0],ei[1],ei[2],file=f)
File "C:\Python24\Lib\traceback.py", line 124, in print_exception
_print(file, 'Traceback (most recent call last):')
File "C:\Python24\Lib\traceback.py", line 13, in _print
file.write(str+terminator)
AttributeError: 'cStringIO.StringI' object has no attribute 'write'

What is 'cStringIO.StringI' anyway? Shouldn't it be 'cStringIO.StringIO'?
See http://docs.python.org/lib/module-cStringIO.html:

"""
Another difference from the StringIO module is that calling StringIO() with
a string parameter creates a read-only object. Unlike an object created
without a string parameter, it does not have write methods. These objects
are not generally visible. They turn up in tracebacks as StringI and
StringO.
"""

Peter

Jul 25 '06 #2
En/na Laszlo Nagy ha escrit:
This program:

import sys
import traceback
import cStringIO

a = 1.0
b = 0.0
try:
c=a/b
except: f = cStringIO.StringIO('')
ei = sys.exc_info()
traceback.print_exception(ei[0],ei[1],ei[2],file=f)
from cStringIO documentation:
Another difference from the StringIO module is that calling
StringIO() with a string parameter creates a read-only object.
Unlike an object created without a string parameter, it does
not have write methods.

HTH
Jul 25 '06 #3
from cStringIO documentation:
Another difference from the StringIO module is that calling
StringIO() with a string parameter creates a read-only object.
Unlike an object created without a string parameter, it does
not have write methods.
Looks like I did not read the manual carefully, overlooked/misunderstood
this and posted too early.
I'm sorry!
Laszlo

Jul 25 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

21 posts views Thread by Paul Rubin | last post: by
1 post views Thread by garyjefferson123 | last post: by
2 posts views Thread by Jonathan Bowlas | last post: by
3 posts views Thread by =?ISO-8859-1?Q?Markus_Sch=F6pflin?= | last post: by
3 posts views Thread by Paul Rubin | last post: by
5 posts views Thread by peppergrower | last post: by
1 post views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.