Questions tagged [stringio]

Use for questions concerning the Python 2 module StringIO or the class StringIO it contains. In Python 3, this refers to the class StringIO of the io module.

Python class StringIO allows to read and write a string buffer (also known as memory files).

355 questions
2
votes
1 answer

How to make cStringIO transparent to another function that expects a real local file

I came up with the following problem: CODE A works right now.. I am saving a png file called chart.png locally, and then I am loading it into the proprietary function (which I do not have access). However, in CODE B, am trying to use…
relima
  • 3,462
  • 5
  • 34
  • 53
2
votes
2 answers

Convert a Python list of lists to a string

How can I best convert a list of lists in Python to a (for example) comma-delimited-value, newline-delimited-row, string? Ideally, I'd be able to do something like this: >import csv >matrix = [["Frodo","Baggins","Hole-in-the-Ground,…
Simon Lepkin
  • 1,021
  • 1
  • 13
  • 25
2
votes
0 answers

MemoryError zipfile in memory

I'm getting MemoryError (out of memory) when zipping files in memory with Python. I'm using cStringIO.StringIO as an in memory buffer stream. Follow the code below: zip_file = cStringIO.StringIO() with zipfile.ZipFile(file=zip_file,…
2
votes
3 answers

Porting from Python 2 to Python 3: 'utf-8 codec can't decode byte'

Hey I tried to port that little snippet to Python 3 from 2. Python 2: def _download_database(self, url): try: with closing(urllib.urlopen(url)) as u: return StringIO(u.read()) except IOError: self.__show_exception(sys.exc_info()) …
Fragkiller
  • 589
  • 2
  • 8
  • 21
2
votes
1 answer

Extracting bz2 file with single file in memory

I have a csv file compressed into a bz2 file that I'm trying to load from a website, decompress, and write to a local csv file by # Get zip file from website archive = StringIO() url_data = urllib2.urlopen(url) archive.write(url_data.read()) #…
Daniel Underwood
  • 2,191
  • 2
  • 22
  • 48
2
votes
1 answer

Is there any advantage to using BytesIO with markdown instead of open / read in Python?

Considering the following code: from markdown import markdown f = open('myfile.md', 'r') html_text = markdown(f.read()) f.close() Is there any speed advantage or disadvantage to using io.BytesIO and markdownFromFile? Or is it a wash? from markdown…
FlipperPA
  • 13,607
  • 4
  • 39
  • 71
2
votes
1 answer

How to load a image into a label without saving to hard drive python Tkinter

I am working on a project where I have a list with a couple of StringIO in it. I want to load those into a Tkinter label but I get this error: IOError: cannot identify image file. I understand that it means it can not find the image file. But how…
2
votes
1 answer

POST StringIO object and open with PIL

When I posted the image load with StringIO, and usd the web.py to obtain the StringIO object, I could not open it with PIL. My POST code is: # encoding:utf-8 import requests from StringIO import StringIO img = open('test.jpg').read() img =…
2
votes
2 answers

How do I pass multiple StringIO into python-pdfkit?

Goal: - Use django templateing language. - Render the template in memory (no disk writes). - Push rendered content to StringIO instance. - Use instance in python-pdfkit. Issue: I keep getting TypeError: coercing to Unicode: need string or buffer,…
cph
  • 458
  • 2
  • 6
  • 24
2
votes
1 answer

Python StringIO is not correctly capturing data from stderr

I have written some unittests that analyze data that is logged with the standard python logging function. Using some of the ideas that I found here: Capture stdout from a script in Python about how to capture data from stderr, I have come up with…
Alexander Marquardt
  • 1,539
  • 15
  • 30
2
votes
2 answers

Sinatra, Twitter, and StringIO

The Twitter API allows you to add media to your tweet via their update_with_tweet method. I am using Sinatra and have my Twitter configurations all set up. I am able to succesfully post tweets with my app. My app reads a webpage, extracts the photos…
kittyminky
  • 478
  • 6
  • 27
2
votes
4 answers

Extract zip to memory, parse contents

I want to read the contents of a zip file into memory rather than extracting them to disc, find a particular file in the archive, open the file and extract a line from it. Can a StringIO instance be opened and parsed? Suggestions? Thanks in…
Captain Caveman
  • 1,448
  • 1
  • 11
  • 24
2
votes
2 answers

How to overcome memory issue when sequentially appending files to one another

I am running the following script in order to append files to one another by cycling through months and years if the file exists, I have just tested it with a larger dataset where I would expect the output file to be roughly 600mb in size. However I…
AEA
  • 213
  • 2
  • 12
  • 34
2
votes
1 answer

How can I get the response body from pycurl multi curl requests

I am unable to get anything but empty responses when performing curl multi requests. No exceptions are thrown, but the response value has no content (commented in the below snippet) Here's a simplified version of my code: from StringIO import…
Tom Manterfield
  • 6,515
  • 6
  • 36
  • 52
2
votes
1 answer

PyGame load cStringIO as image

So, I've tried a few solutions on the net for this but each one returns a different error. Most recently I've decided to try something like: import cStringIO, pygame, os from pygame.locals import * pygame.init() mainClock =…
John
  • 65
  • 6