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

Use of readline function with Python StringIO module

I am trying to read a file from an FTP site and process one line at a time. I write from the FTP server to a StringIO object and call the readline function, but this returns the entire file, rather that the first line. I downloaded the file to my…
DaWisePug
  • 129
  • 1
  • 6
3
votes
1 answer

redirecting python logging messages with streams

I want to redirect logging messages to some handling method (e.g. in order so save all messages in a queue). Currently I'm trying to make use of logging.StreamHandler in order to write to a StringIO and then read it somewhere else. In my case this…
frans
  • 8,868
  • 11
  • 58
  • 132
3
votes
1 answer

Finding the content type of the uploaded file in rails

I am working on ruby on rails. I am trying to do a file attachment (image/audio/video) . So i have a common method like byteArray = StringIO.new(File.open("path").read) Is it possible to find the content type of the byteArray to check whether the…
useranon
  • 29,318
  • 31
  • 98
  • 146
3
votes
3 answers

should chained calls be used in favor of more explicit assignments?

our team have to snippet like below: this: buf = StringIO.StringIO() gzip.GzipFile(fileobj=buf, mode='wb').write(foo) ... and this one: buf = StringIO.StringIO() tmp = gzip.GzipFile(fileobj=buf, mode='wb') tmp.write(foo) ... which one is more…
dennisyuan
  • 171
  • 1
  • 10
2
votes
2 answers

Create DataFrame from String "like" data

I have a text data that look like this: 3,"a","b","e","r"\n4,"1","2","5","7"\n4,"23","45","76","76" I want to transfor it to be table like this: a b e r 1 2 5 7 23 45 76 76 I've tried to use a pandas data frame for that, but the data size is…
Kirana
  • 21
  • 3
2
votes
1 answer

Python - Creating Zip in stream that exceeds RAM

I'm trying to create a zip file on the fly of a directory and return it to the user over a Flask App. The below works great for smaller directories but I'd also like to achieve this with large directories full of images (>20GB). def return_zip(): …
James Watson
  • 35
  • 1
  • 4
2
votes
1 answer

Problem with StringIO importing ee, although it could be imported alone

I am trying to import the module ee to use the google earth engine according to the documentation on the dedicated website. https://developers.google.com/earth-engine/guides/python_install I got this error: import ee ModuleNotFoundError …
2
votes
2 answers

Process mixed bytes data into python list

I am reading data remote .dat files for EDI data processing. Original Data is some string bytes: b'MDA1MDtWMjAxOS44LjAuMDtWMjAxOS44LjAuMDsyMDIwMD.........' Used decode as below... byte_data = base64.b64decode(byte_data) Gave me this below byte…
NinjaBat
  • 370
  • 4
  • 20
2
votes
1 answer

How to capture prints in real time from function?

I want to capture all the prints and do something like return them but keep running the function. I found this method but it only returns the prints when the code is finished. f = io.StringIO() with redirect_stdout(f): # my code return…
Yoav
  • 73
  • 4
2
votes
1 answer

Persist a pandas dataframe to a Postgres SQL table using StringIO

I am trying to persist a dataframe into a Postgres table with no luck. I have a table table1 with fields f1,f2, f3 df = pd.DataFrame({"f1":["A", "B"], "f2": [1, 2], "f3": ["p", "f"] }) buffer =…
SeriousGal
  • 21
  • 2
2
votes
1 answer

In Python, how to write back a stringIO text file to a zip archive, then back to bytea field in PostgreSQL?

A relative noob to Python, I've successfully pulled a text file, out of a zip archive, contained in a PostgreSQL bytea field, using this code: myzip = ZipFile(StringIO(rv[0]["archivefield"]), 'a') data = myzip.read("content.txt",'a') # *** WORK ON…
DrLou
  • 649
  • 5
  • 21
2
votes
1 answer

Save a pandas df into a file-like object with gzip compression

I am trying to save a pandas DF into a in-memory json_buffer and the load the file to S3 using the following code: json_buffer = StringIO() df.to_json(json_buffer, orient='records', date_format='iso', compression='gzip') json_file_name =…
Tomer Shalhon
  • 185
  • 1
  • 11
2
votes
0 answers

Parse GML as geopandas dataframe

I'm trying to parse the following gml as geopandas dataframe, which did work when trying to parse a csv string as pandas dataframe. import geopandas as gpd from io import StringIO gml = '
Daan
  • 349
  • 4
  • 16
2
votes
0 answers

Howto emulate pipe-like buffer in Python?

Is there a way to use StringIO buffer like pipe with lazy write? Is there a way to hook a function to be called when End Of File/String occurs on the StringIO object to append next lines that can be read? Already read lines should by disposed. Or is…
Hans Ginzel
  • 8,192
  • 3
  • 24
  • 22
2
votes
1 answer

StringIO for directories: How to create in-memory directory in Python

How can I create an in-memory directory in python, like how StringIO creates in-memory files? I'm trying to verify the signature of a file using python-gnupg. I want to create a gnupghome directory in-memory so that its safe (other non-root…
Michael Altfield
  • 2,083
  • 23
  • 39