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
1
vote
2 answers

xhtml2pdf: Output generated PDF as in-memory object (its bytes)

I'm working with Python 3, Django and the xhtml2pdf package. I want to create a PDF from an HTML string, but I don't want to write the PDF on disk, but rather just to get its bytes from memory, as in using BytesIO or StringIO. I've read the…
Xar
  • 7,572
  • 19
  • 56
  • 80
1
vote
2 answers

"No columns to parse from file" error when trying to transform string into Pandas dataframe

I have a string object ("textData") which contains CSV data. I'm able to save it as CSV by: with open(fileName, "w") as text_file: print(textData, file=text_file) but I would like to work with the data in pandas before saving the csv.…
younggotti
  • 762
  • 2
  • 15
1
vote
0 answers

read list of strings as file, python3

I have a list of strings, and would like to pass this to an api that accepts only a file-like object, without having to concatenate/flatten the list to use the likes of StringIO. The strings are utf-8, don't necessarily end in newlines, and if…
some bits flipped
  • 2,592
  • 4
  • 27
  • 42
1
vote
1 answer

Unable to read StringIO object created by json.dump()

I am trying to write a list of dictionaries to a StringIO object with json.dump() in Python 3. The objective is to create a pandas dataframe from a JSON "file" without actually saving it to disk. I can't seem to read anything from the StringIO…
Captain Jack Sparrow
  • 971
  • 1
  • 11
  • 28
1
vote
1 answer

How to read variable contents instead of file path?

I have a Python function [1] which requires the file path pointing to the file it has to process as an argument. However, I have a string variable containing the contents of the respective file. I don't want to create a file only to read it with…
Hein Schnell
  • 322
  • 5
  • 15
1
vote
0 answers

Saving memory with requests / pandas / StringIO

I'm reading a .csv file from the web with requests and feeding it via StringIO to pandas.read_csv(). The Google Apps Engine gave me a warning about high memory usage so I decided to trace memory allocation with memory_profiler: Line # Mem usage …
1
vote
1 answer

Python: Redirect various output sections to separate variables

I'm trying to create a mechanism to redirect print outputs to a number of variables. Following code simulates what I'm looking for :- import sys import io class MultiOut(object): def __init__(self, stream_out): self.terminal =…
BotKnight
  • 93
  • 2
  • 7
1
vote
1 answer

Merge Pandas Dataframes (ie: Orders and Inventory), then re-adjust Inventory

I have an order list with a separate inventory system (Google Sheets). Using Pandas, I'm trying to merge the two for an efficient "pick list" and have had some mild success. However, in testing (adding multiple quantities for an order, having…
1
vote
0 answers

Are cStringIO.StringIO and io.BytesIO interchangeable in Python 2?

I'm currently working in a Python 2 codebase, but I'd like to write code in a way where moving to Python 3 would be simple. I'm trying to refactor code to use cStringIO instead of StringIO for reading in file bytes, since it's the same API but…
Arya
  • 1,382
  • 2
  • 15
  • 36
1
vote
0 answers

Python 3 Stringio + PIL + Requests get image from url

I am heving troubles migrating to python 3. This is my code: from io import StringIO from PIL import Image import requests r = requests.get(imagen_url) imagen = Image.open(StringIO(r.content)) It used to work on python 2. This is the error I…
1
vote
2 answers

Jupyter Notebook io.StringIO as output

Input Blast_aa_mc = qblast("blastp","nr", aa_mc[2]) Blast_aa_mc Output <_io.StringIO at 0x12a1a48> What is _io.StringIO? and what does it mean? What I was expecting was some sort of string or array. Is there a better way to do this?
1
vote
0 answers

Convert a list of dicts to CSV and attach to email using SendGrid

I'm trying to retrieve some data and mail it out from within a Google Cloud Function using SendGrid I tried convert the data as a list of dictionaries (with the same, flat, structure) to CSV as detailed here but this fails as the filesystem is read…
kilokahn
  • 1,136
  • 2
  • 18
  • 38
1
vote
2 answers

Python pip3 install StringIO Not Found for url: https://pypi.org/simple/stringio/

I am running python version 3.6.9 and pip3 version 9.0.1. when i execute the command pip3 install StringIO It returns the error Collecting StringIO Exception: Traceback (most recent call last): File…
Erik hoeven
  • 1,442
  • 6
  • 26
  • 41
1
vote
1 answer

Storing image from StringIO to a file creates a distorted image

I stored an image to StringIO from PIL. When I store it to a file from stringIO, it doesn't produce the original image. Code: from PIL import Image from cStringIO import StringIO buff=StringIO() img = Image.open("test.jpg") …
TheGuardener
  • 361
  • 5
  • 11
1
vote
1 answer

How to make secure ldap connection with encrypted key?

I am writing below ldap client side code to connect to secure ldap server. import ldap ldap.set_option(ldap.OPT_X_TLS_KEYFILE, 'a/b/key.txt') But my key.txt contains a encrypted key which needs passphrase. Could you please let me know how do I pass…
Kalyan Kumar
  • 399
  • 3
  • 14