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

how to log to StringIO from a multiprocessing Process

I just can't get a StreamHandler working with StringIO to accept logging from a Process. The strange thing is that a stream to stdout works just fine. This is my code: from time import sleep import logging import multiprocessing from io import…
Jev
  • 1,163
  • 10
  • 13
3
votes
2 answers

What is the purpose of using StringIO in DecisionTree

I am writing a decision tree and the following code is a part of the complete code: def show_tree(tree, features, path): f = io.StringIO() export_graphviz(tree, out_file=f, feature_names=features) …
Hasham Beyg
  • 313
  • 3
  • 11
3
votes
1 answer

Convert pytesseract string output to pandas df

I have been given receipts from Subway detailing sales, workers, etc throughout the day and need to extract the data for a management class. I took pictures of the receipts and processed them with pytesseract into a string separated by \n but now…
N.Fisher
  • 154
  • 1
  • 9
3
votes
1 answer

Bulk insert using PostgreSQL copy_from, psycopg2 and StringIO

I need to insert bunch of lines in Postgres table from python script and am using an advice to use copy_from for performance purpose. import io data_io = io.StringIO() # here I have a loop which is omitted for…
Agenobarb
  • 143
  • 2
  • 10
3
votes
2 answers

StringIO example does not work

I try to understand how works numpy.getfromtxt method and io.StringIO. On the officical website(https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.genfromtxt.html#numpy.genfromtxt) I found some examples. Here is one of them: s =…
Alex Rozhnov
  • 199
  • 3
  • 12
3
votes
2 answers

Reading from StringIO without resetting position

I have a test code with the following: with open('master.log') as f: print(f.read(8)) print(f.read(8)) This prints as: >> pi@raspberrypi:~/workspace/Program $ sudo python test.py >> 12/29/20 >> 17 12:52 This has different prints as you can…
Helder Esteves
  • 451
  • 4
  • 13
3
votes
2 answers

python gzip file in memory and upload to s3

I am using python 2.7... I am trying to cat two log files , get data from specific dates using sed. Need to compress the files and upload them to s3 without making any temp files on the system, sed_command = "sed -n '/{}/,/{}/p'".format(last_date,…
supervirus
  • 97
  • 1
  • 3
  • 10
3
votes
1 answer

Ruby writing to a file in memory (not actually writing to it)

So I have this program that works with passing around a string (this string is the path of the file it is supposed to read) Now I have a method that has to open that file. change the text with Gsub and than output that file again (The original file…
3
votes
1 answer

Real file objects slower than StringIO and cStringIO?

StringIO has the following notes in its code: Notes: - Using a real file is often faster (but less convenient). - There's also a much faster implementation in C, called cStringIO, but it's not subclassable. The "real file is often faster" line…
Vanessa Phipps
  • 2,205
  • 1
  • 18
  • 22
3
votes
1 answer

Why ruby StringIO does not give different encodings

Why in the following code I get different encodings ? >>> require 'stringio' >>> a = StringIO.new('toto') >>> a.read(2).encoding => # >>> a.read.encoding => # >>> a.read.encoding => #
ptitpoulpe
  • 684
  • 4
  • 17
3
votes
2 answers

StringIO Cannot Identify Image File Error

I'm using the following code to retrieve an image online: import Image import urllib2 import cStringIO url = 'http://storage.googleapis.com/bloomsky-img/k65x5Kvpyc3W08jBqJ1kqZqnnZapoQ==.jpg' img = urllib2.urlopen(url).read() # error occurred when…
J Freebird
  • 3,664
  • 7
  • 46
  • 81
3
votes
1 answer

Create zip archive without save archiving file to disk in Ruby

I tried to create zip archive without save archiving file to disk. So First I write method with save to disk: begin file = Zip::File.open("#{file_name}.zip", Zip::File::CREATE) save_file file_name file.add(file_name, file_name) rescue IOError…
khusnetdinov
  • 421
  • 5
  • 16
3
votes
2 answers

Python StringIO.write doesn't like integer zero?

Why can stream.write output pretty much anything other than zero? from StringIO import StringIO v0 = 0 v1 = 1 a = [1, 0, v1, v0, "string", 0.0, 2.0] stream = StringIO() for v in a: stream.write(v) stream.write('\n') print…
Peter Krnjevic
  • 1,070
  • 15
  • 20
3
votes
2 answers

Ruby converting String to File for uploading to FTP

Currently we have a method that returns a string with a formatted CSV file. string = EXPORT.tickets We need to upload this csv file to a ftp server like so ftp = Net::FTP.new(server, username, password) ftp.putbinaryfile(string) however, the…
ruevaughn
  • 1,319
  • 1
  • 17
  • 48
3
votes
1 answer

Send multiple StringIO from PIL Image in POST requests with Python

I have a stored picture on my computer. I open it using the Python Image module. Then I crop this image into several pieces using this module. To conclude, I would like to upload the image via a POST request on a website. Because that small images…
Delgan
  • 18,571
  • 11
  • 90
  • 141