Questions tagged [cstringio]

A simple fast partial StringIO replacement in Python 2

This module provides a simple useful replacement for the StringIO module that is written in C. It does not provide the full generality of StringIO, but it provides enough for most applications and is especially useful in conjunction with the pickle module.

https://docs.python.org/2/library/stringio.html#module-cStringIO

Note that cStringIO was removed from Python 3 (ref: here).

33 questions
110
votes
3 answers

python 3.x ImportError: No module named 'cStringIO'

How do I solve an ImportError: No module named 'cStringIO' under Python 3.x?
jvi
  • 1,111
  • 2
  • 7
  • 5
32
votes
1 answer

Confusing about StringIO, cStringIO and ByteIO

I have googled and also search on SO for the difference between these buffer modules. However, I still don't understand very well and I think some of the posts I read are out of date. In Python 2.7.11, I downloaded a binary file of a specific format…
wsdzbm
  • 3,096
  • 3
  • 25
  • 28
11
votes
1 answer

tempfile.TemporaryFile vs. StringIO

I've written a little benchmark where i compare different string concatenating methods for ZOCache. So it looks here like tempfile.TemporaryFile is faster than anything else: $ python src/ZOCache/tmp_benchmark.py 3.00407409668e-05…
pcdummy
  • 133
  • 1
  • 6
10
votes
1 answer

pandas unable to read from large StringIO object

I'm using pandas to manage a large array of 8-byte integers. These integers are included as space-delimited elements of a column in a comma-delimited CSV file, and the array size is about 10000x10000. Pandas is able to quickly read the…
castle-bravo
  • 1,389
  • 15
  • 34
8
votes
1 answer

Python cStringIO take more time than StringIO in writing (performance of string methods)

In my way to profile string methods in python so that I can use the fastest one. I have this code to test string concatenation in files, StringIO, StringIO and normal string. #!/usr/bin/env python #title : pythonTiming.py #description …
Muhammad Yusuf
  • 397
  • 1
  • 15
7
votes
3 answers

Why is StringIO object slower than real file object?

I'm looking through the source of StringIO where it says says some notes: Using a real file is often faster (but less convenient). There's also a much faster implementation in C, called cStringIO, but it's not subclassable. StringIO just like a…
JanuaryStar
  • 103
  • 1
  • 5
6
votes
1 answer

Write in memory object to S3 via boto3

I am attempting to write files directly to S3 without creating a local file which is then uploaded. I am using cStringIO to generate a file in memory, but I am having trouble figuring out the proper way to upload it in boto3. def…
bubba4399
  • 73
  • 1
  • 5
6
votes
1 answer

in-place replacement in StringIO

How do I replace a string with another inside a StringIO? - I've heard it's possible if they're the same length. Attempt: from cStringIO import StringIO c = 'can\nhaz\nfoo' sio = StringIO(c) for line in sio: if line == 'haz\n': #…
A T
  • 13,008
  • 21
  • 97
  • 158
4
votes
2 answers

python how to concat stringio objects?

Because I don't want to get into passing variables into a function that modifies its input variables; I have a couple of functions that return new StringIO.StringIO() objects, with some text output each. I want to concatenate these outputs together…
ThorSummoner
  • 16,657
  • 15
  • 135
  • 147
3
votes
2 answers

Reading from StringIO without resetting position

I have a test code with the following: with open('master.log') as f: print(f.read(8)) print(f.read(8)) This prints as: >> pi@raspberrypi:~/workspace/Program $ sudo python test.py >> 12/29/20 >> 17 12:52 This has different prints as you can…
Helder Esteves
  • 451
  • 4
  • 13
3
votes
2 answers

How to change image format without writing it to disk using Python Pillow

I got Pillow image that i got from the Internet: response= urllib2.urlopen() img = Image.open(cStringIO.StringIO(response.read())) I want to use it with tesserocr but it wont work with GIF images. If I save the image as PNG…
Lord_JABA
  • 2,545
  • 7
  • 31
  • 58
3
votes
1 answer

Real file objects slower than StringIO and cStringIO?

StringIO has the following notes in its code: Notes: - Using a real file is often faster (but less convenient). - There's also a much faster implementation in C, called cStringIO, but it's not subclassable. The "real file is often faster" line…
Vanessa Phipps
  • 2,205
  • 1
  • 18
  • 22
3
votes
2 answers

Python - Pyramid and matplotlib - Cannot Have More Than One View Output A SVG?

I am developing a Python Pyramid application where I am intending to create more than one SVG image to chart statistics using pie charts. In my testing I find that one SVG view works correctly and as soon as I add a second SVG output view, and a…
localhost
  • 375
  • 1
  • 3
  • 15
2
votes
2 answers

no module named StringIO

I have python 3.6. I want to execute python file named 'operation.py' from another python file named 'run.py'. In operation.py I do from cStringIO import StringIO. PyCharm shows me a warning that there is no module named StringIO. I know that since…
user9399101
  • 71
  • 1
  • 1
  • 3
2
votes
2 answers

Encoding in a in-memory stream or how does TextIOBase work?

I am currently reading the documentation for the io module: https://docs.python.org/3.5/library/io.html?highlight=stringio#io.TextIOBase Maybe it is because I don't know Python well enough, but in most cases I just don't understand their…
Daniel
  • 3,092
  • 3
  • 32
  • 49
1
2 3