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

Python StringIO - selectively place data into stdin

We're using a bit of compiled python code that we don't have the source to. The code prompts for user input and we're trying to automate that portion. Basically asks for username, password, then some various questions depending on certain…
sjmh
  • 3,330
  • 4
  • 23
  • 27
1
vote
1 answer

pyqt : QPixmap save to StringIO?

I try to POST QPixmap image bia http. To do that, I have to let QPixmap save to temporary file and read it as python file class, do POST works. But I think that there is another way to POST QPixmap. Guess it, QPixmap save to StringIO(or something…
Hyun-geun Kim
  • 919
  • 3
  • 22
  • 37
1
vote
4 answers

Python application won't exit when using stringIO and pygame.mixer.music.load()

I'm using StringIO to stream music data, but it appears that when I run with pygame.mixer.music.load(), my application won't exit. Even if I use close(): def PlaySong(self, song_id): song = StringIO.StringIO(resp.read()) …
AdamL
  • 41
  • 4
1
vote
2 answers

BytesIO with python v2.5

Question: How do I get a byte stream that works like StringIO for Python 2.5? Application: I'm converting a PDF to text, but don't want to save a file to the hard disk. Other Thoughts: I figured I could use StringIO, but there's no mode parameter (I…
tgray
  • 8,826
  • 5
  • 36
  • 41
1
vote
2 answers

Capture output from subprocess.call that I have no control over

I'm testing a piece of Python code that uses subprocess.call(), so I have no control over that function call. I need to capture the output from that system call to do assertions. I tried to set os.stdout to a StringIO object, but that doesn't…
Addison
  • 1,065
  • 12
  • 17
0
votes
1 answer

Translate standard output memory file to string of English text as if a print command were being used

I am running a find command for a particular file that I know exists. I would like to get the path to that file, because I don't want to assume that I know where the file is located. My understanding is that I need to redirect stdout, run the…
jesuis
  • 2,246
  • 3
  • 19
  • 17
0
votes
1 answer

Passing python StringIO to C++ stringstream using swig

I've got some python code that generates a StringIO variable. I'd like to pass this variable to a C++ function using a stringstream parameter (on the assumption C++ stringstream is the closest match to a python StringIO). Is there a simple way using…
user1215017
  • 1
  • 1
  • 2
0
votes
2 answers

Alternative to urllib.urlencode for encoding a URL

I'm trying to send a request to an API that only accepts XML. I've used elementtree.SimpleXMLWriter to build the XML tree and it's stored in a StringIO object. That's all fine and dandy. The problem is that I have to urlencode the StringIO object in…
Hartley Brody
  • 8,669
  • 14
  • 37
  • 48
0
votes
0 answers

Only last line of output being retrieved from stdout (contextlib, sys.stdout, and capture magic)

I'm trying to capture terminal output to store it elsewhere. Specifically, I'm trying to retrieve the training loss from sklearn.linear_model.LogisticRegression. This is unfortunately not stored anywhere, but is printed when verbose=1. I am trying…
0
votes
1 answer

Stringio 3.0.6 does not execute properly with arm64 on M1 MacOS

I'm trying to install stringio 3.0.6 as a part of project dependencies tree via bundle install, but apparently it does not work as it should because of the error mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'). The…
Sviat Kuzhelev
  • 1,758
  • 10
  • 28
0
votes
2 answers

How to get all previous print in Python

I'm currently using some functions to store all print in Python And it get all print AFTER the function has finished Here is a sample snippet import io import sys import time import traceback def return_std(func): def wrapper(*args, **kwargs): …
Dacian Peng
  • 75
  • 1
  • 6
0
votes
1 answer

PYTHON: Can't get the .csv file from zip

I want to get the zip file from get request response and unzip the content to get .CSV file inside. And then upload the .CSV file to Google Sheets. How can I do it? Here is my code, it is giving me the TypeError: a bytes-like object is required, not…
0
votes
0 answers

Writing the console output into a StringIO buffer from a thread (step-wise)

I have a function that consist of a loop, from which I control the thread with semaphores: import sys from io import StringIO import threading # Create a semaphore object sem = threading.Semaphore() def my_function(event_set=True): # Start a…
JrCaspian
  • 297
  • 3
  • 15
0
votes
0 answers

Getting "Xref table not zero-indexed. ID numbers for objects will be corrected" warning

I have the following code (comments explain what is occuring): import os from io import StringIO from PyPDF2 import PdfFileReader # Path to the directory containing the PDF files pdf_dir = '/path/to/pdf/files' # Iterate over the files in the…
ahhhgetit
  • 7
  • 3
0
votes
0 answers

store all logging data in memory python

I have looked solutions for my query but couldn't find related to my answer. Below is my code: #test.py def log_setup(): stream = io.StringIO() #logging.handlers.BufferingHandler(capacity=float("inf")) …
VJ P
  • 45
  • 5