草庐IT

read_buffer

全部标签

python 3 : reading bytes from stdin pipe with readahead

我想读取字节。sys.stdin以文本模式打开,但它有一个可用于读取字节的缓冲区:sys.stdin.buffer.我的问题是,当我将数据通过管道传输到Python时,如果我想要预读,我似乎只有2个选项,否则我会得到一个io.UnsupportedOperation:Fileorstreamisnotseekable.从sys.stdin读取缓冲文本,将该文本解码为字节,然后寻找(sys.stdin.read(1).decode();sys.stdin.seek(-1,io.SEEK_CUR).由于输入流中的不可编码字节而无法接受。使用peek从stdin的缓冲区中获取一些字节,将其切

python - 如何在 Windows 上使用 Python 的 Protocol Buffer ?

我一直在尝试在我的Python程序中使用ProtocolBuffer,但无法让它工作。我正在运行Windows8机器并尝试过Python2.7.6和Python3.3。我下载了适用于Python的二进制ProtocolBuffer编译器,并使用它从我的myProto.proto文件生成了myProto_pb2.py,但是当我运行Python时出现以下错误程序:在“importmyProto_pb2”行中,使用2.5版ProtocolBuffer中的Python2.7.6时出现以下错误:fromgoogle.protobufimportdescriptoras_descriptorImp

Python3 CSV writerows,TypeError : 'str' does not support the buffer interface

我正在将以下Kaggle代码翻译成Python3.4:在输出CSV文件时的最后几行,predictions_file=open("myfirstforest.csv","wb")open_file_object=csv.writer(predictions_file)open_file_object.writerow(["PassengerId","Survived"])open_file_object.writerows(zip(ids,output))predictions_file.close()print('Done.')有一个类型错误TypeError:'str'doesno

python - 找到 TypeError : coercing to Unicode: need string or buffer, 列表

我正在尝试启动并运行数据解析脚本。就数据操作而言,它是有效的。我想做的是设置它,这样我就可以用一个命令输入多个用户定义的CSV。例如>pythonscript.pyOne.csvTwo.csvThree.csv如果您对如何自动命名输出CSV有任何建议,那么如果input=test.csv,output=test1.csv,我会也很感激。获取TypeError:coercingtoUnicode:needstringorbuffer,listfound为线forlineincsv.reader(open(args.infile)):我的代码:importcsvimportpprintpp

python - pandas.read_excel 参数 "sheet_name"不工作

根据pandasdocfor0.21+,pandas.read_excel有一个参数sheet_name允许指定读取哪个工作表。但是当我试图从excel文件中读取第二张表时,无论我如何设置参数(sheet_name=1,sheet_name='Sheet2'),数据框始终显示第一张工作表,并且传递索引列表(sheet_name=[0,1])不会返回数据框字典,但仍会返回第一张工作表。这可能是什么问题? 最佳答案 看起来您使用的是旧版本的Python。所以尝试改变你的代码df=pd.read_excel(file_with_data,

python - 类型错误 : Type str doesn't support the buffer API # find method?

这是我的输入:..........JimCramer‏@jimcramer26NovLovethisspirited&rigorous$TSLAdefense!RT@InfennonLabs:Whyaretheseidiotsselling#tslaaretheythatblind?@jimcramerFavorited5times...........例如这个“输入”在我的input变量中。这是我的代码:start_link=input.find('如果我运行它,我会得到以下错误:start_link=input.find('我该如何解决这个问题?注意:我的输入变量的类型是:

python - 您如何使用 pd.read_clipboard 读取带有列表的数据框?

这是来自另一个question的一些数据:positivenegativeneutral1[marvel,moral,bold,destiny][][view,should]2[beautiful][complicated,need][]3[celebrate][crippling,addiction][big]我首先要做的是在所有单词上添加引号,然后:importastdf=pd.read_clipboard(sep='\s{2,}')df=df.applymap(ast.literal_eval)有没有更聪明的方法来做到这一点? 最佳答案

python - 类型错误 : 'str' does not support the buffer interface

importhashlibinfile=open("P:\\r.mp3",'r+b')data=infile.readline()hash=hashlib.md5()hash.update(data)hash_digest=hash.hexdigest()print(hash_digest)#hash_digest=hash_digest.encode('utf-8')print(hash_digest)withopen("lt.txt",'ab')asoutfile:outfile.write(hash_digest+'\n')#errorherewithopen("syncDB.t

python - 在 Pandas 中使用 read_csv 时精度丢失

我在一个文本文件中有以下格式的文件,我正在尝试将其读入pandas数据框。895|2015-4-23|19|10000|LA|0.4677978806|0.4773469340|0.4089938425|0.8224291972|0.8652525793|0.6829942860|0.5139162227|如您所见,输入文件中的float后有10个整数。df=pd.read_csv('mockup.txt',header=None,delimiter='|')当我尝试将它读入数据框时,我没有得到最后4个整数df[5].head()00.46779810.25816520.8603843

【Git】git出现:git@gitee.com: Permission denied (publickey). fatal: Could not read from rem以及IDEA中配置GIT

gitpush时候如果出现如下错误,是因为少了一个known_hosts文件,此时输入yes回车之后,生成了缺少了的known_hosts文件,便可解决这个问题。若使用sshclone或者push时候出现git@gitee.com:Permissiondenied(publickey).fatal:Couldnotreadfromremote类的错误,表示git需要进行ssh配置,下面以gitee为例:解决方法:步骤1:添加/生成SSH公钥,码云提供了基于SSH协议的Git服务,在使用SSH协议访问项目仓库之前,需要先配置好账户/项目的SSH公钥。绑定账户邮箱:gitconfig--globa