473,657 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cStringIO.Strin gIO 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.Strin gIO('')
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\Li b\traceback.py" , line 124, in print_exception
_print(file, 'Traceback (most recent call last):')
File "C:\Python24\Li b\traceback.py" , line 13, in _print
file.write(str+ terminator)
AttributeError: 'cStringIO.Stri ngI' object has no attribute 'write'

What is 'cStringIO.Stri ngI' anyway? Shouldn't it be 'cStringIO.Stri ngIO'?

Laszlo

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

import sys
import traceback
import cStringIO

a = 1.0
b = 0.0
try:
c=a/b
except:
f = cStringIO.Strin gIO('')
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\Li b\traceback.py" , line 124, in print_exception
_print(file, 'Traceback (most recent call last):')
File "C:\Python24\Li b\traceback.py" , line 13, in _print
file.write(str+ terminator)
AttributeError: 'cStringIO.Stri ngI' object has no attribute 'write'

What is 'cStringIO.Stri ngI' anyway? Shouldn't it be 'cStringIO.Stri ngIO'?
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.Strin gIO('')
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
2259
by: Paul Rubin | last post by:
I've always found the string-building idiom temp_list = for x in various_pieces_of_output(): v = go_figure_out_some_string() temp_list.append(v) final_string = ''.join(temp_list) completely repulsive. As an alternative I suggest
1
1763
by: garyjefferson123 | last post by:
I want to accept a cStringIO object in a function in a python extension module. How do I do this? e.g., static PyObject *myfunc(PyObject *self, PyObject *args) { PyObject *cstringio; if (!PyArg_ParseTuple(args, "O:cStringIO", &cstringio)) { PyErr_SetString(PyExc_ValueError, "value must be a
2
26356
by: Jonathan Bowlas | last post by:
Hi listers, I've written this little script to generate some html but I cannot get it to convert to a string so I can perform a replace() on the >, < characters that get returned. from StringIO import StringIO def generator_file(rsspath,titleintro,tickeropt): scripter=StringIO()
3
1561
by: =?ISO-8859-1?Q?Markus_Sch=F6pflin?= | last post by:
Hello, I just stumbled accross a difference between cStringIO in Python 2.4 and 2.5. You can no longer feed arrays to cStringIO. Python 2.4: ---%<--- ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on Python 2.4.3 (#69, Apr 11 2006, 15:32:42)
3
3210
by: Paul Rubin | last post by:
Python 2.5 (r25:51908, Oct 6 2006, 15:24:43) on linux2 Type "help", "copyright", "credits" or "license" for more information. 'a' 'a' u'a' 'a\x00\x00\x00' I would have thought StringIO and cStringIO would return the same result for this ascii-encodeable string. Worse:
12
1644
by: Stefan Scholl | last post by:
After an hour searching for a potential bug in XML parsing (PyXML), after updating from 2.4 to 2.5, I found this one: $ python2.5 Python 2.5 (release25-maint, Dec 9 2006, 14:35:53) on linux2 Type "help", "copyright", "credits" or "license" for more information. Traceback (most recent call last): File "<stdin>", line 1, in <module>
1
1725
by: grbgooglefan | last post by:
I am in a perculiar situation. I want to use PyRun_SimpleString for creating Python functions in embedded Python in C++. But there could be cases when Python function code compilation could fail & PyRun_SimpleString will return -1 as return status. At this time, it prints the error message to sys.stderr. So, we do not have any control or cannot use that message to show to user to correct the errors in the function code. I could assign an...
6
6000
by: sebastian.noack | last post by:
Hi, is there a way to or at least a reason why I can not use tarfile to create a gzip or bunzip2 compressed archive in the memory? You might might wanna answer "use StringIO" but this isn't such easy as it seems to be. ;) I am using Python 2.5.2, by the way. I think this is a bug in at least in this version of python, but maybe StringIO isn't just file-like enough for this "korky" tarfile module. But this would conflict with its...
5
2793
by: peppergrower | last post by:
I've been experimenting with the 'with' statement (in __future__), and so far I like it. However, I can't get it to work with a cStringIO object. Here's a minimum working example: ### from __future__ import with_statement import cStringIO teststring='this is a test'
0
8384
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8302
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8820
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8718
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.