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
4
votes
1 answer

pysftp putfo creates an empty file on SFTP server but not streaming the content from StringIO

My code first writes lines to a CSV in io.StringIO(): fileBuffer = io.StringIO() # write header header_writer = csv.DictWriter(fileBuffer, fieldnames=columnNames) header_writer.writeheader() # write lines writer = csv.writer(fileBuffer,…
C.Tomas
  • 451
  • 2
  • 7
  • 15
4
votes
3 answers

google storage python API - uploading an StringIO object

I succeeded in uplaoding a file to the google storage, but I would like to skip the creation of a file and use StringIO instead and create the file on the google storage directly. Since I'm new to python, I just tried to use the standard method that…
Tomislav Mikulin
  • 5,306
  • 4
  • 23
  • 36
4
votes
1 answer

python flask restfull receive image

Hi I am having trouble receiving a file on my flask server from my python client I am saving the screenshot in memory but am unable to receive it on the server end. I appreciate any help I can get I am lost with what my requests.post has to…
w40
  • 43
  • 1
  • 1
  • 4
4
votes
1 answer

Python convert StringIO to binary

I have a simple task: in luigi, store pandas dataframe as a csv in dropbox, using dropbox-python sdk Usually (with S3, for example) you can use StringIO as a file-like in-memory object. It also works great with pandas df.to_csv() Unfortunately,…
Philipp_Kats
  • 3,872
  • 3
  • 27
  • 44
4
votes
2 answers

Python's StringIO for Clojure

Is there something equivalent to Python's StingIO for Clojure? I'm trying to write a report generating/literate programming system similar to Sweave and Pweave for Clojure. I'm currently using a temp file, but I'd prefer using something similar to…
Matti Pastell
  • 9,135
  • 3
  • 37
  • 44
4
votes
2 answers

Read ZipFile from URL into StringIO and parse with panda.read_csv

I'm trying to read ZipFile data from a URL and via StringIO parse the data inside the ZipFile as csv using pandas.read_csv r = req.get("http://seanlahman.com/files/database/lahman-csv_2014-02-14.zip").content file = ZipFile(StringIO(r)) salaries_csv…
Winston
  • 63
  • 1
  • 6
4
votes
2 answers

How to reattach sys.stdout to console window in python?

My python 3 doodling went like this: import io, sys sys.stdout = io.StringIO() # no more responses to python terminal funnily enough My question is how to reattach so when I pass in 1+1 for example it'll return with 2 to the console? This is in the…
user1561108
  • 2,666
  • 9
  • 44
  • 69
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
4
votes
2 answers

Mock stdout in Python

I am new to Python unit testing, and especially Mock. How would I mock an object that I could do the following with? I just need an object that does not make the loop crash, in order to complete the test. for ln in theMock.stdout.readlines() I…
Daniel Larsson
  • 6,278
  • 5
  • 44
  • 82
4
votes
1 answer

Python Flask: Download a file generated on the fly AND print a response

I followed the tutorial to stream a file generated on the fly in Flask. Now I want to display a message using the same data that was used to generate the file. It's a large dataset and I can not afford to download it both to generate the file and…
A User
  • 812
  • 2
  • 7
  • 21
4
votes
1 answer

Error Remains After Running 2to3.py on a Module

I used the 2to3.py script to convert several of my files to Python 3 a while back. I believe I need to run all fixers, so my command included -f all -f buffer -f idioms -f set_literal -f ws_comma -w I tried to run my converted code with Python 3,…
Matthew Stamy
  • 1,114
  • 1
  • 7
  • 9
4
votes
1 answer

relative seek for io.StringIO in python3

I am trying to refactor a python 2 package for use with python-3.x. The package uses StringIO.StringIO under python 2 and makes some use of the object's relative seek method, with statements like flob.seek(-1, 1). Unfortunately, the seek method of…
Anaphory
  • 6,045
  • 4
  • 37
  • 68
4
votes
1 answer

How does one add string to tarfile in Python3

I have problem adding an str to a tar arhive in python. In python 2 I used such method: fname = "archive_name" params_src = "some arbitrarty string to be added to the archive" params_sio = io.StringIO(params_src) archive =…
luk32
  • 15,812
  • 38
  • 62
4
votes
1 answer

python : post data within stringIO through poster?

params = {'file': open("test.txt", "rb"), 'name': 'upload test'} datagen, headers = poster.encode.multipart_encode(params) request = urllib2.Request(upload_url, datagen, headers) result = urllib2.urlopen(request) I use poster library to POST for…
Hyun-geun Kim
  • 919
  • 3
  • 22
  • 37
4
votes
1 answer

Python(2.6) cStringIO unicode support?

I'm using python pycurl module to download content from various web pages. Since I also wanted to support potential unicode text I've been avoiding the cStringIO.StringIO function which according to python docs: cStringIO - Faster version of…
Ivan Kovacevic
  • 1,322
  • 12
  • 30