cstringio

Real file objects slower than StringIO and cStringIO?

点点圈 提交于 2019-12-03 22:17:15
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 slower under some circumstances, though I'm not doing any concatenating here. The test writes a given

pandas unable to read from large StringIO object

这一生的挚爱 提交于 2019-12-03 12:31:37
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 to a DataFrame of 8-bit integers. I have tried the following: intdata = pd.DataFrame(strdata

Python Capture reply from powershell

有些话、适合烂在心里 提交于 2019-12-02 10:04:47
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("testitem.txt"))) old_stdout = sys.stdout sys.stdout = mystdout = StringIO() for key, value in my_data

python 3.x ImportError: No module named 'cStringIO'

﹥>﹥吖頭↗ 提交于 2019-11-26 07:40:40
问题 How do I solve an ImportError: No module named \'cStringIO\' under Python 3.x? 回答1: From Python 3.0 changelog; The StringIO and cStringIO modules are gone. Instead, import the io module and use io.StringIO or io.BytesIO for text and data respectively. From the Python 3 email documentation it can be seen that io.StringIO should be used instead: from io import StringIO from email.generator import Generator fp = StringIO() g = Generator(fp, mangle_from_=True, maxheaderlen=60) g.flatten(msg) text