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

Strange output using Pandas when converting StringIO with read_csv

When the pandas CSV reader function 'read_csv" is used to convert StringIO values strange characters ('.1') are being appended at the end of the second field when delimiting certain fields. The desired results is the first test, but all the fields…
NobleVision
  • 107
  • 1
  • 8
1
vote
0 answers

How to transform PIL.Image object to buffer string?

sbuf = StringIO() sbuf.write(decoded_file) pimg = Image.open(sbuf) print pimg.size cimage = StringIO() pimg.seek(0) pimg.save(cimage,'jpeg') contents = cimage.getvalue() if contents == decoded_file: print '1------->> ok!' 'decoded_file' is a…
AirChen
  • 11
  • 1
1
vote
1 answer

get the size in bytes of a StringIO object

Is it possible to get the size in bytes of a StringIO object? or should i write it to disk every time i want to get its size? I have searched a lot but without success. There .sizeof() but i don't think that is what i want. I am iterating over a…
sdikby
  • 1,383
  • 14
  • 30
1
vote
2 answers

Amend value at the end of a line on a text file - python

34512340 plain brackets 0.50 30 56756777 100mm bolts 0.20 0 90673412 L-shaped brackets 1.20 30 I have this text file and I want to take the value on the end of each line, do something to it and then write it back…
1
vote
3 answers

Unittesting - replacing filepaths with StringIO objects

I am trying to unittest parsing functions which take a filepath and return some of the file contents. I would like to be able to pass these functions strings of data for testing purposes. I understand that I can pas csv.reader() either StringIO or a…
David258
  • 697
  • 2
  • 6
  • 15
1
vote
2 answers

Creating PDF using pydot

I got the below code from Visualizing a Decision Tree - Machine Learning import numpy as np from sklearn.datasets import load_iris from sklearn import tree iris = load_iris() test_idx = [0, 50 , 100] train_target =…
python novice
  • 379
  • 1
  • 4
  • 18
1
vote
1 answer

Write png to xlsx file with XlsxWriter in python?

Following the guide for XlsxWriter here: Docs I have tried using Pillow to get the png file. Then write to the worksheet using the guide from the link above. I tried to use StringIO. f = Image.open('/opt/folder/' + 'cc.png') output =…
Helpme
  • 505
  • 3
  • 7
  • 18
1
vote
1 answer

Create Python array.array Object from cStringIO Object

I want to create an array.array object from a cStringIO object: import cStringIO, array s = """ """ f = cStringIO.StringIO(s) a = array.array('c') a.fromfile(f, len(s)) But I get the following…
aaronstacy
  • 6,189
  • 13
  • 59
  • 72
1
vote
1 answer

What is `StringIO` in the context of RSpec testing (Ruby on Rails)?

What is StringIO in Ruby on Rails? I'm trying to understand another SO answer that references StringIO, but its over my head. I would suggest using StringIO for this and making sure your SUT accepts a stream to write to instead of a…
tim_xyz
  • 11,573
  • 17
  • 52
  • 97
1
vote
2 answers

Django. Download Image with requests - edit with PIL - save to model

I'm having trouble with this process: I want to download an image using requests, then crop it with PIL and then save it to the a model ImageField. This is what I have now: from django.core.files.base import ContentFile import requests from StringIO…
Alejandro Veintimilla
  • 10,743
  • 23
  • 91
  • 180
1
vote
1 answer

printing floats to io.StringIO in Python 2/3

I'm trying to write a Python program that works in both Python 2.7 and Python 3.*. I have a case where I use StringIO, and according to Python-Future's cheatsheet on StringIO, all I have to to is to use the Python 3-style io module. The problem is…
user824425
1
vote
1 answer

How to handle tokenization errors?

Please find below the piece of code that I use to tokenize a string. strList = list(token[STRING] for token in generate_tokens(StringIO(line).readline) if token[STRING]) I get an error that reads like:- raise TokenError, ("EOF in multi-line…
leba-lev
  • 2,788
  • 10
  • 33
  • 43
1
vote
0 answers

Send an image using PIL and StringIO

I've just started using PIL, StringIO and Pygame, therefore I have some troubles with getting the results I want. I try to make a screen sharing software, and in order to achieve that I need to be able to send an image from one computer to another…
1
vote
2 answers

python json dump writability "not write able"

So this is the second piece of a problem with my program, but a completely different issue, thanks to the helpful person who suggested JSON as a better method to do what I wanted.... Anyway... some success with JSON. The program also changed theme,…
Ryan Harger
  • 47
  • 1
  • 9
1
vote
2 answers

Python: Optimizing Images in Memory (StringIO & POpen with jpegoptim)

I'm trying to compress images without touching disk using the STDIN version of various libraries(jpegoptim in this example). This code does not return an optimized(jpegoptim compressed) image. Can someone please help or explain why this usage of…
ryan83
  • 13
  • 4