By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,239 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

cStringIO.StringIO has no write method?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.