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

how to assert a binary multiline value in python using pytest

I have the following scenario using python3: type(file_pointer) => then file_pointer.get_value() # result below b'simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard…
John D
  • 285
  • 3
  • 22
0
votes
1 answer

How can i convert this lists object into a dataframe?

I have something which lokos like (called lines) [' id\t Name\t Type\t User\t Q\t country\t Final-score\t Progress\t website', 'abcde\t jen\t …
Maths12
  • 852
  • 3
  • 17
  • 31
0
votes
2 answers

Capturing runpy.run_module stdout

I'm unable to capture stdout of runpy.run_module into a variable using StringIO. To demonstrate the problem, I created a script called runpy_test.py (code below) using an arg switch; 0 = do not redirect stdout. 1 = redirect using StringIO, capture…
0
votes
2 answers

Path too long for StringIO, but not for text

I would like to copy data into a pandas dataframe using StringIO as opposed to a text file. Some files will be really big and i'd rather not have big text files and then delete. Using StringIO seems like a much nicer solution. If I do this the…
costa rica
  • 85
  • 1
  • 12
0
votes
2 answers

How do I pass raw untrusted text to feedparser.parse method in Python?

I am trying to use feedparser to parse text which I download using asyncio aiohttp library The feed text is available HERE (Large document, hence not pasting here) The documentation of feedparser.parse method mentions that you should not send an…
PirateApp
  • 5,433
  • 4
  • 57
  • 90
0
votes
0 answers

Pass StringIO output as argument for os.path like object in subprocess popen

I am trying to execute sql code in sqlcmd through subprocess. The "-i" option of sqlcmd expects a file. I am converting the sql code into file stream with StringIO and passing it as a argument to popen, but it fails import subprocess from subprocess…
Aravinth C
  • 43
  • 1
  • 7
0
votes
1 answer

TypeError in_io.BytesIO with Python3

I'm trying to read a file in io but it returns an error. It's giving me a TypeError which I'm not able to solve. This is the code I'm using: str_summary = pd.read_sql("SELECT * FROM '" + str(overall_summary) + "'", conn) s =…
fakeMake
  • 738
  • 8
  • 18
0
votes
0 answers

How do I 'properly' use executable programs in python

Problem I have a third-party program (written in C++) that I want to use in my Python code. The program takes three arguments as follows: $ program.exe [arg1] [input_file] [output_file] The way I'm using it for now is by writing the input file, use…
chickenNinja123
  • 311
  • 2
  • 11
0
votes
1 answer

Avoiding memory error when reading large csv file

I'm trying to read a large csv file (25 GB) onto a google cloud instance using the following method: from google.cloud import storage from io import StringIO client = storage.Client() bucket = client.get_bucket('bucket') blob =…
Alex Martin
  • 507
  • 1
  • 3
  • 9
0
votes
0 answers

Does StringIO create a file on disk?

In the following example: import sqlite3 from io import StringIO def init_sqlite_db(app): # Read database to tempfile con = sqlite3.connect(app.config['SQLITE_DATABASE']) tempfile = StringIO() for line in con.iterdump(): …
Paragon512
  • 143
  • 8
0
votes
1 answer

How to use a StringIO() object as the program's stdin to send a string to an input statement,

I would like be able to reroute the stdin of my program to a StringIO() object so that I can simulate user response to an input statement. newstdin = StringIO() sys.stdin = newstdin newstdin.write("hey") newstdin.seek(0) response =…
TheFluffDragon9
  • 514
  • 5
  • 11
0
votes
1 answer

StringIO appears to behave different when initialising from a buffer as opposed to writing data into it line by line

I'm trying to read some data and parse it out as CSV. The data format in question comes with a wacky first line that I first need to get rid of. delimiter = None with open('data.csv', 'r', encoding='latin1') as fd: input1 =…
0
votes
0 answers

How to fix TypeError: initial_value must be str or None, not bytes using StringIO

I've got the error message initial_value must be str or None, not bytes and i do not know how to fix it. I face with that after changing to python 3. Moreover I change the import to from io import StringIO Here is my code : def…
gtopal
  • 544
  • 1
  • 9
  • 35
0
votes
2 answers

Reading a big csv file into dataframe

I have a large csv file (of 13 GB) that I wish to read into a dataframe in Python. So I use: txt = pd.read_csv(r'...file.csv', sep=';', encoding="UTF-8", iterator = True, chunksize=1000) It works just fine, but the data is contained in a…
Siva Kg
  • 59
  • 8
0
votes
1 answer

Using unittest to check "--help" flag output

I have some code that parses command line options using argparse. For example: # mycode.py import argparse def parse_args(): parser = argparse.ArgumentParser('my code') # list of arguments # ... # ... return…
berkelem
  • 2,005
  • 3
  • 18
  • 36