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
13
votes
4 answers

Strange "BadZipfile: Bad CRC-32" problem

This code is simplification of code in a Django app that receives an uploaded zip file via HTTP multi-part POST and does read-only processing of the data inside: #!/usr/bin/env python import csv, sys, StringIO, traceback, zipfile try: import…
Marc Abramowitz
  • 3,447
  • 3
  • 24
  • 30
12
votes
4 answers

Python pandas NameError: StringIO is not defined

I am unable to read data in Pandas: Input: import pandas as pd data = 'a,b,c\n1,2,3\n4,5,6' pd.read_csv(StringIO(data),skipinitialspace=True) Output: NameError:name 'StringIO' is not defined Please let me know why the error occurred and also let…
Abhishek
  • 515
  • 1
  • 5
  • 12
11
votes
1 answer

How can I pass a Python StringIO() object to a ZipFile(), or is it not supported?

I have a StringIO() file-like object, and I am trying to write it to a ZipFile(), but I get this TypeError: coercing to Unicode: need string or buffer, cStringIO.StringI found Here is a sample of the code I am using: file_like = StringIO() archive…
Brian
  • 1,703
  • 3
  • 17
  • 23
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
2 answers

How to write a string to file on ftp with pysftp?

I have a large xml file stored in a variable. I want to write it directly to an ftp using pysftp. I believe I need to use the pysftp.putfo and this needs a file like object. Here is a minimal example: from io import StringIO from pysftp import…
Stian
  • 1,221
  • 1
  • 19
  • 26
10
votes
3 answers

How to use string as input for csv reader without storing it to file

I'm trying to loop through rows in a csv file. I get csv file as string from a web location. I know how to create csv.reader using with when data is stored in a file. What I don't know is, how to get rows using csv.reader without storing string to a…
Fejs
  • 2,734
  • 3
  • 21
  • 40
10
votes
1 answer

Unicode problems when using io.StringIO to mock a file

I am using an io.StringIO object to mock a file in a unit-test for a class. The problem is that this class seems expect all strings to be unicode by default, but the builtin str does not return unicode strings: >>> buffer = io.StringIO() >>>…
Björn Pollex
  • 75,346
  • 28
  • 201
  • 283
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
10
votes
1 answer

SQLite3 connection from StringIO (Python)

I am wondering if anyone knows a way to generate a connection to a SQLite database in python from a StringIO object. I have a compressed SQLite3 database file and I would like to decompress it using the gzip library and then connect to it without…
horriblyUnpythonic
  • 853
  • 2
  • 14
  • 34
10
votes
3 answers

python StringIO doesn't work as file with subrpocess.call()

I'm working with subprocess package to call some external console commands from a python script, and I need to pass file handlers to it to get stdout and stderr back separately. The code looks like this roughly: import subprocess stdout_file =…
alexykot
  • 699
  • 1
  • 8
  • 21
10
votes
6 answers

How to loop until EOF in Python?

I need to loop until I hit the end of a file-like object, but I'm not finding an "obvious way to do it", which makes me suspect I'm overlooking something, well, obvious. :-) I have a stream (in this case, it's a StringIO object, but I'm curious…
Ben Blank
  • 54,908
  • 28
  • 127
  • 156
9
votes
3 answers

How to fix "ImportError: cannot import name 'StringIO'"

python version is 3.6.6 and pandas_datareader version is 0.7.0 when i import pandas_datareader, an error occurs like below. C:\PycharmProjects\Demo\venv\Scripts\python.exe C:/PycharmProjects/Demo/stock.py Traceback (most recent call last): File…
김장환
  • 91
  • 1
  • 1
  • 3
9
votes
1 answer

How to use 'io.StringIO' with 'print >>'?

I got the following error: Second line. Traceback (most recent call last): File "./main.py", line 8, in print >>output, u'Second line.' TypeError: unicode argument expected, got 'str' When I run the following code. I don't know what…
user1424739
  • 11,937
  • 17
  • 63
  • 152
9
votes
1 answer

Convert PILLOW image into StringIO

I'm writing a program which can receive images in a variety of common image formats but needs to examine them all in one consistent format. It doesn't really matter what image format, mainly just that all of them are the same. Since I need to…
Jed Estep
  • 585
  • 1
  • 4
  • 15
9
votes
2 answers

File upload Base64 encoded string in PaperClip using Rails

I have at base64 encoded string of a image file. I need to save it using Paper Clip My Controller code is @driver = User.find(6) encoded_file = Base64.encode64(File.open('/pjt_path/public/test.jpg').read) decoded_file =…
Amal Kumar S
  • 15,555
  • 19
  • 56
  • 88
1 2
3
23 24