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
0
votes
2 answers

'rU' mode for StringIO (new-line character seen in unquoted field)

I am trying to parse gzip files line by line : with gzip.open(obj.get()['Body'])as f: for line in f: line=StringIO(line.decode("utf-8")) line=csv.reader(line,delimiter=',') for line1 in line: #some logic But…
Liz Hi
  • 3
  • 1
  • 5
0
votes
1 answer

Direct way to slice a string with f.read() to ultimately read in csv as pandas dataframe

I have a .csv file which I want to open and ultimately save it as a pandas dataframe. This file has some junk text above the data frame per se, whose header starts at the string Sample_ID. I wrote a code which does the job in multiple steps, and I…
BCArg
  • 2,094
  • 2
  • 19
  • 37
0
votes
0 answers

Capture IPython output in a Python Kernel

I want to capture the output produced by IPython terminal in a Python terminal. As all the testing takes place using a Python Kernel. I know about the IPython magic function. %%capture Is there a way to use these magic functions as context manager…
0
votes
1 answer

How to base64 encode a html_string

AIM I am attempting to encode a folium choropleth as StringIO. I am basing my answer of a related query. I have checked the answers here and here. ERROR AttributeError: 'bytes' object has no attribute 'encode' CODE views.py def get_choropleth(self,…
Darcy
  • 575
  • 2
  • 8
  • 21
0
votes
0 answers

Pillow throws error on save with StringIO

In some tutorials was explained to use StringIO in Pillow save method. but when I use this testcode: from PIL import Image from io import StringIO, BytesIO photo = Photo.objects.get(pk=1) bytes = BytesIO() string = StringIO() image =…
Asara
  • 2,791
  • 3
  • 26
  • 55
0
votes
1 answer

StringIO() argument 1 must be string or buffer, not cStringIO.StringIO

I have a function that's reading a content object into a pandas dataframe. import pandas as pd from cStringIO import StringIO, InputType def create_df(content): assert content, "No content was provided, can't create dataframe" if not…
staten12
  • 735
  • 3
  • 9
  • 20
0
votes
0 answers

Return Zip file with HttpResponse using StringIO, Django, Python

I'm trying to return a zip file with HttpResponse, using StringIO() because i'm not storing in DB or Harddrive. My issue is that my response is returning 200 when i request the file, but the OS never ask me if i want to save the file, or the file is…
0
votes
1 answer

Error expected type StringIO, got str instead

I'm trying to bulk insert data into my postgres database using the copy_from function from psycopg2. To use this function, I'm trying to put a list of tuples into a file-like object using io.StringIO (python 3.x). def __insert_cpe_dic__(self,…
Melvin
  • 407
  • 5
  • 16
0
votes
1 answer

AttributeError: 'NoneType' object has no attribute 'content'

I want to download a zip file using python, I am getting the while running following code import requests, zipfile, StringIO zip_file_url = "http://www.blog.pythonlibrary.org/wp-content/uploads/2012/06/wxDbViewer.zip" r = None try: r =…
0
votes
0 answers

AttributeError: 'cStringIO.StringO' object has no attribute 'getValue'

I am new in python (but not in php) and doing some test to learn it by myself. When I run the code with urls in the array, I get this error: print req[1].getValue() AttributeError: 'cStringIO.StringO' object has no attribute 'getValue' When I check…
zeflex
  • 1,487
  • 1
  • 14
  • 29
0
votes
1 answer

memory leak caused bu stringio in flask with nginx

@app.route('/') def index(): strIO = StringIO.StringIO() strIO.write('Hello from Dan Jacob and Stephane Wirtel !') strIO.seek(0) return send_file(strIO, attachment_filename="testing.txt", as_attachment=True) in…
valiant wang
  • 75
  • 10
0
votes
1 answer

Appending files to a StringIO Tar archive one at a time

I am writing code that utilizes the StringIO object and rubygems/package which includes TarWriter and TarReader. My end goal is to be able to call a method add_file to add/append a file to the archive and then call a method read_all_files to read…
randy newfield
  • 1,221
  • 3
  • 25
  • 38
0
votes
1 answer

Cannot Iterate over cStringIO

In a script, I'm writing lines to a file, but some of the lines may be duplicates. So I've created a temporary cStringIO file-like object, which I call my "intermediate file". I write the lines to the intermediate file first, remove duplicates, then…
Alureon
  • 179
  • 1
  • 3
  • 14
0
votes
1 answer

PIL cannot identify image file for a Google Drive image streamd into io.BytesIO

I am using the Drive API to download an image. Following their file downloading documentation in Python, I end up with a variable fh that is a populated io.BytesIO instance. I try to save it as an image: file_id =…
0
votes
1 answer

Reading TEXT type from SAP HANA into python

I am working on a project that requires me to get data from a SAP HANA database. I utilized SAP Cloud Connector and PyHDB for the job. I execute my select statement and obtain the result data. One of the fields is a TEXT type, containing large…
spdasilv
  • 101
  • 1
  • 1
  • 7