cstringio

tempfile.TemporaryFile vs. StringIO

◇◆丶佛笑我妖孽 提交于 2020-06-25 03:39:13
问题 I've written a little benchmark where i compare different string concatenating methods for ZOCache. So it looks here like tempfile.TemporaryFile is faster than anything else: $ python src/ZOCache/tmp_benchmark.py 3.00407409668e-05 TemporaryFile 0.385630846024 SpooledTemporaryFile 0.299962997437 BufferedRandom 0.0849719047546 io.StringIO 0.113346099854 concat The benchmark code i've been using: #!/usr/bin/python from __future__ import print_function import io import timeit import tempfile

Confusing about StringIO, cStringIO and ByteIO

一世执手 提交于 2020-01-12 06:31:26
问题 I have googled and also search on SO for the difference between these buffer modules. However, I still don't understand very well and I think some of the posts I read are out of date. In Python 2.7.11, I downloaded a binary file of a specific format using r = requests.get(url) . Then I passed StringIO.StringIO(r.content) , cStringIO.StringIO(r.content) and io.BytesIO(r.content) to a function designed for parsing the content. All these three methods are available. I mean, even if the file is

Python Capture reply from powershell

限于喜欢 提交于 2019-12-31 05:15:12
问题 The code below works when typed manually however when I run the program.py nothing prints. My ultimate goal is to retrieve this data from user pc to create an easy way to recreate shortcuts.... My users somehow lose them lol import smtplib, os, subprocess, sys from string import ascii_uppercase from cStringIO import StringIO data = os.popen(r"dir %userprofile%\desktop\*.lnk* /s/b").read() file = open("testitem.txt", "w") file.write(data) file.close() my_data = dict(zip(ascii_uppercase,open(

Python cStringIO take more time than StringIO in writing (performance of string methods)

烂漫一生 提交于 2019-12-22 04:39:15
问题 In my way to profile string methods in python so that I can use the fastest one. I have this code to test string concatenation in files, StringIO, StringIO and normal string. #!/usr/bin/env python #title : pythonTiming.py #description : Will be used to test timing function in python #author : myusuf #date : 19-11-2014 #version : 0 #usage :python pythonTiming.py #notes : #python_version :2.6.6 #============================================================================== import time import

Python using cStringIO with foreach loop

北城以北 提交于 2019-12-11 05:58:16
问题 I want to iterate over lines cStringIO object, however it does not seem to work with foreach loop. To be more precise the behavior is as if the collection was empty. What am I doing wrong? example: Python 2.7.12 (default, Aug 29 2016, 16:51:45) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import cStringIO >>> s = cStringIO.StringIO() >>> import os >>> s.write("Hello" + os.linesep + "World" + os.linesep) >>> s

Why is StringIO object slower than real file object?

拥有回忆 提交于 2019-12-07 03:13:25
问题 I'm looking through the source of StringIO where it says says some 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. StringIO just like a memory file object, why is it slower than real file object? 回答1: Python's file handling is implemented entirely in C. This means that it's quite fast (at least in the same order of magnitude as native C code). The StringIO library, however, is

Real file objects slower than StringIO and cStringIO?

别等时光非礼了梦想. 提交于 2019-12-05 07:29:01
问题 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 seemed really odd to me: how could writing to disk beat writing to memory? I tried profiling these different cases and got results that contradict these docs, as well as the answer to this question. This other question does explain why cStringIO is

Why is StringIO object slower than real file object?

你。 提交于 2019-12-05 06:57:17
I'm looking through the source of StringIO where it says says some 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. StringIO just like a memory file object, why is it slower than real file object? Python's file handling is implemented entirely in C . This means that it's quite fast (at least in the same order of magnitude as native C code). The StringIO library, however, is written in Python. The module itself is thus interpreted, with the associated performance penalties. As you know,

Python cStringIO take more time than StringIO in writing (performance of string methods)

血红的双手。 提交于 2019-12-05 06:53:22
In my way to profile string methods in python so that I can use the fastest one. I have this code to test string concatenation in files, StringIO, StringIO and normal string. #!/usr/bin/env python #title : pythonTiming.py #description : Will be used to test timing function in python #author : myusuf #date : 19-11-2014 #version : 0 #usage :python pythonTiming.py #notes : #python_version :2.6.6 #============================================================================== import time import cStringIO import StringIO class Timer(object): def __enter__(self): self.start = time.time() return self

pandas unable to read from large StringIO object

孤街醉人 提交于 2019-12-04 19:05:56
问题 I'm using pandas to manage a large array of 8-byte integers. These integers are included as space-delimited elements of a column in a comma-delimited CSV file, and the array size is about 10000x10000. Pandas is able to quickly read the comma-delimited data from the first few columns as a DataFrame, and also quickly store the space-delimited strings in another DataFrame with minimal hassle. The trouble comes when I try to cast transform the table from a single column of space-delimited strings