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

How to append two StringIO objects?

X = ABC (example data) print(type(x)) ---> Y = ABC (example data) print(type(x)) ---> Z=X+Y Is it possible to append of these types data= Z.getvalue() How to achieve this with or without…
Rohit
  • 23
  • 3
-1
votes
2 answers

python exec function not returning echo statement

I have a setup that looks as following: from io import StringIO from contextlib import redirect_stdout f = StringIO() with redirect_stdout(f): exec("""'echo "test"'""") s = f.getvalue() print("return value:",s) Is there a reason why the return…
Yes
  • 339
  • 3
  • 19
-1
votes
1 answer

UnboundLocalError: local variable 'qn' referenced before assignment

I'm getting the error "UnboundLocalError: local variable 'qn' referenced before assignment" on running the code. Why is that? How can I correct it? I'm new to tkinter so please try to keep it simple. This is part of the code for a game I was…
JGZ
  • 307
  • 1
  • 3
  • 13
-1
votes
1 answer

python convert list of strings to CSV

I have a list of strings like so: ls = [ 'Header1,Header2,Header3', 'Value1,Value2,Value3', 'Value4,Value5,Value6' ] And I want to convert it to a CSV or CSV Object with the…
DBA108642
  • 1,995
  • 1
  • 18
  • 55
-1
votes
1 answer

Read in CSV trying to skip rows but having problems deleting first 6 rows

I am trying to read in the following file, and am having problems reading in the csv. The CSV file contains a lot of information at the top of the file prior to the header of the data. I have tried skiprows, and content to skip the stuff at the…
Dave K
  • 1
  • 1
-1
votes
1 answer

read string as a file using io.StringIO

I need to make a string to be read by bibtexparser's parsing_read. As far as I understood the module, it only reads file, not stream, so I have done: text = "Some text" with open("/tmp/bibtmp.bib", "w") as bibfile: …
BaRud
  • 3,055
  • 7
  • 41
  • 89
-1
votes
1 answer

please help me identify the meaning of this error

I'm trying to loop through the contents of a decrypted file held in the variable "decrypt" and write those contents into a MySQL database table (data_1). Please help me identify what this error means and also a possible work around the error. >>>…
user3530362
  • 89
  • 1
  • 1
  • 5
-1
votes
2 answers

Bug in StringIO module python using numpy

Very simple code: import StringIO import numpy as np c = StringIO.StringIO() c.write("1 0") a = np.loadtxt(c) print a I get an empty array + warning that c is an empty file. I fixed this by adding: d=StringIO.StringIO(c.getvalue()) a =…
member555
  • 797
  • 1
  • 13
  • 40
-2
votes
1 answer

Difference in file size between StringIO and actual File Size

I have following code import StringIO import os output = StringIO.StringIO("c:/temp/file.txt") position = output.tell() output.seek(0, os.SEEK_END) size = output.tell() output.seek(position, os.SEEK_SET) print size It displays size as 22 But…
user3376169
  • 405
  • 1
  • 5
  • 17
-2
votes
2 answers

How to re-arrange string lines in python

I have string like below mentioned and contain n number of lines per group and I would like to arrange the string as mentioned below .. real 51.85ms sys 22.41ms usr 29.70ms [www.ms786.com] 2345 sunset follow Multidd 567890KB real …
Koushur
  • 167
  • 1
  • 9
1 2 3
23
24