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

What is >> for after print command in python 2?

import cStringIO output = cStringIO.StringIO() output.write('First line.\n') print >>output, 'Second line.' # Retrieve file contents -- this will be # 'First line.\nSecond line.\n' contents = output.getvalue() What does >>output in the print…
Deck Trout
  • 161
  • 11
2
votes
0 answers

How to call Python Cmd instance remotely/programmatically, replacing stdin and stdout pipes?

I'd like to have a Python Cmd instance running in a separate thread, and be able to write input and read output from other parts of my program. In the constructor of Cmd, it is possible to specify stdin(default: sys.stdin) and stdout(default…
celtichindu
  • 33
  • 1
  • 4
1
vote
2 answers

What is StringIO() used for in this script?

I just started using Django and Python and I'm trying to build a photo app. This script is generating thumbnails and I'd like to do that myself. Unfortunately I don't understand what StringIO() is doing. The Python Docs aren't very helpful to me in…
JasonTS
  • 2,479
  • 4
  • 32
  • 48
1
vote
1 answer

How ot write a Faiss index to memory?

I want to write a faiss index to back it up on the cloud. I can write it to a local file by using faiss.write_index(filename, f). However, I would rather dump it to memory to avoid unnecessary disk IO. I tried passing in a StringIO or ByteIO stream,…
Lizozom
  • 2,161
  • 2
  • 21
  • 38
1
vote
2 answers

Downloading a file into memory

I am writing a python script and I just need the second line of a series of very small text files. I would like to extract this without saving the file to my harddrive as I currently do. I have found a few threads that reference the TempFile and…
jimstandard
  • 1,067
  • 2
  • 10
  • 17
1
vote
0 answers

Unexplained ValueError("No tables found") occurring using Python pandas.read_html

Problem: An unexplained ValueError("No tables found") is being raised intermittently when using pandas read_html in conjunction with a proxy-configuration to parse data from multiple webpages (Python 3.x). Background: To access each webpage,…
DAK
  • 116
  • 1
  • 10
1
vote
1 answer

Error deploying Streamlit app "Could not find a version that satisfies the requirement StringIO"

I'm new in the use of streamlit. I have an app and it work in the local way. But I tried to deploy this app and it seems that the library "io" isn't recognize. Does anyone know how to fix it ? I've already tried several things but it doesn't…
Mtine
  • 21
  • 4
1
vote
1 answer

Why do I get an EmptyDataError while read_csv from string?

import random import string import csv from ntropy_sdk import SDK, Transaction from io import StringIO import pandas as pd transactions = """description amount iso_currency_code Aktywna Warszawa S 21.07 PLN Crv*Ww Beauty Lukasz Mich …
biGmazi
  • 11
  • 3
1
vote
1 answer

get index per ID - from example data using text input to pandas dataframe? easily reproducible

Text can be used as input to pandas dataframes to make easily reproducible examples for testing solutions.1 import pandas as pd from io import StringIO txt= """ ID,datetime,value AB-CL-34,07/10/2022 10:00:00,5 AB-CL-34,07/10/2022 11:15:10,7…
Johan
  • 186
  • 15
1
vote
1 answer

How to check what lineending a StringIO file is using?

I had a method that detects line endings def getLineEnding(filename): ret = "\r\n" with open(filename, 'r') as f: f.readline() ret = f.newlines return ret In order to be able to test it without using real files, I…
klutt
  • 30,332
  • 17
  • 55
  • 95
1
vote
1 answer

Pandas: Empty Dataframe when reading from StringIO with read_csv

Following is the StringIO object value csv_log_stream.getvalue() Raw Output '"2022-06-04 12:02:40,248",azure_functions_worker,INFO,"Successfully processed FunctionLoadRequest, request ID: 5bc6ee11-9eaa-4479-902a-3e037ac08503, function ID:…
Benison Sam
  • 2,755
  • 7
  • 30
  • 40
1
vote
2 answers

Cannot extract URLs from a text file

I'm trying to parse an online text file's contents then extract all URLs. Everything works fine except the URL extraction part. It doesn't happen. I tried the same process on a local file, and it worked. What is wrong? COMMAND import requests import…
1
vote
1 answer

Python loop to remove duplicates + original from the csv import?

So I have a csv file I want to import and want to skip importing both the duplicate and the original line from the csv file based on a user number in the first column and I'm using the StringIO module. The way I'm doing it currently is below which…
teightdev
  • 7
  • 4
1
vote
2 answers

How to add a long list of headers and rows to a StringIO

I want to generate a StringIO in my tests using this list of headers and rows but my syntax creates a set of nested lists. row = ['0ceaf6ef-35b0-4f5b-ad11-02f7c50c8387', '30 - Day Business Loan', '500000.00',...] headers = ['Application UID',…
Anjayluh
  • 1,647
  • 1
  • 13
  • 22
1
vote
1 answer

Can't use readline() in StringIO

I want to write a string to a StringIO() object and then read it line by line; I tried two ways and none of them produced any output. What am I doing wrong? Creating object, writing to it and check if it worked: from io import…
LizzAlice
  • 678
  • 7
  • 18