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

Size of Python IO Stream

import io string_out = io.StringIO() string_out.write("hello") print(string_out.lenght()) I want to know size of string_out StringIO. Is there any method in StringIO that support this?
Newton8989
  • 300
  • 1
  • 4
  • 22
1
vote
1 answer

TarFile.extractall() processes fine but doesn't create any new files or directories

Version: Python 2.7 OS: MacOS Mojave IDE: Pycharm Community 2019.2 I'm having trouble downloading tar.gz files from pypi.org/project and unzipping them. The use case for this is that we can't use any actual package management, so we have to…
Cdhippen
  • 615
  • 1
  • 10
  • 32
1
vote
1 answer

How to upload url to s3 bucket using StringIO and put_object method with boto3

I need to upload URLs to an s3 bucket and am using boto3. I thought I had a solution with this question: How to save S3 object to a file using boto3 but when I go to download the files, I'm still getting errors. The goal is for them to download as…
topplethepat
  • 531
  • 6
  • 23
1
vote
2 answers

Reading a line that includes tabs

I was obtained a file from https://www.clres.com/db/parses/oec/abaft.parse using urllib3. It has tabs and then \r\n. In Python 2.7, I was using StringIO but this isn't available in Python 3.7. I tried to use IO since StringIO has been…
KenLit
  • 33
  • 6
1
vote
0 answers

StringIO with BOM

I have a CSV file in memory that I've read using ftp.getbinaryfile() in Net::FTP. I am using the SmarterCSV gem which requires a file or readline StringIO object. I keep getting a BOM that appears in my row headers... and I'm trying to use StringIO…
Tallboy
  • 12,847
  • 13
  • 82
  • 173
1
vote
1 answer

String buffer fails to write data to database table

I am porting a mongo database over to a PostgreSQL one and I came across with an issue. I am using psycopg2's COPY_FROM, which takes as arguments a file object, the table to write to and other optional arguments. My original code looked like the…
GRoutar
  • 1,311
  • 1
  • 15
  • 38
1
vote
3 answers

How to escape from the standard output redirection in Python

I want to process a live output of a thirdparty script, printing some lines that match a pattern but skipping others: def thirdparty_code(): from random import choice stuff = ['keep: important stuff', 'ignore: boring stuff'] while True: …
krassowski
  • 13,598
  • 4
  • 60
  • 92
1
vote
2 answers

DataFrame to String

import sys if sys.version_info[0] < 3: from StringIO import StringIO else: from io import StringIO import pandas as pd TESTDATA = StringIO(txt) df = pd.read_csv(TESTDATA,names=['col1']) where txt="The lion (Panthera leo) is a species in…
1
vote
0 answers

How to convert byte string to a text file?

I'm trying to run this code. It is giving me the output in bytes. I want to know how to convert bytes to a text file def convert(fname,pages): if not pages: pagenums = set() else: pagenums = set(str(pages)) output =…
1
vote
0 answers

Problems Reading Zip of Shapefiles without loading memory

I've been trying to adapt Andrew Gaidus shapefile reading routine for my needs. The Jupyter Notebook I'm using acts like it partitioned the disk of my MacBook Pro so I can't read or write to disk. Gaidus has a good procedure for avoiding using…
Larry Field
  • 63
  • 1
  • 2
  • 8
1
vote
1 answer

On zipfile read of shapefile from URL, fault for initial value not str

Using Python 3.5, following example for reading shapefile zipfile from URL and updating for P3.5. Code is below. I've looked at other cases and attempted to append .decode('utf-8') and that does not help. dls =…
Larry Field
  • 63
  • 1
  • 2
  • 8
1
vote
1 answer

Can I resolve "InvocationException: GraphViz's executables not found" without adding anything to system PATH?

I am running the following code: from io import StringIO dot_data = StringIO() export_graphviz(DT, out_file=dot_data, filled=True, rounded=True, special_characters=True) graph =…
bernando_vialli
  • 947
  • 4
  • 12
  • 27
1
vote
1 answer

Is there such a thing as opening a StringIO for writing?

I am trying to use RSpec to test a class that writes to a file. But I want the tests to be fast, so instead of using a real file and write to disk I want to use StringIO in tests and write to memory. In a very simplified way, let's say I have this…
Xirux Nefer
  • 830
  • 1
  • 7
  • 19
1
vote
2 answers

Django response that contains a zip file with multiple csv files

I have a algorithm that outputs a list of tuples which is ready to be written into a csv file. I'm trying to write 3 csv files (through StringIO so no writing to disk) and then zip them altogether. After that I want to attach that to the response of…
JChao
  • 2,178
  • 5
  • 35
  • 65
1
vote
2 answers

Suppose I have a StringIO file. How can I use python-magic to check its file type?

import StringIO import magic m = magic.Magic() thefile = StringIO.StringIO(request.raw_post_data) # I got this from Django. ajax file uploader. what now?
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080