草庐IT

bytes_write

全部标签

python - 使用pyinstaller时出错: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff

我在使用pyinstaller编译PyQt代码时遇到问题。我用这一行来编译:c:\Anaconda3\Scripts\pyinstaller.exe-y-F--distpath="."MyQt.py然后我收到此错误消息:File"c:\anaconda36bis\lib\site-packages\PyInstaller\hooks\hook-zmq.py",line18,inhiddenimports.extend(collect_submodules('zmq.backend'))File"c:\anaconda36bis\lib\site-packages\PyInstaller

Python3 写入 gzip 文件 - 内存 View : a bytes-like object is required, 不是 'str'

我想写一个文件。根据文件的名称,这可能会或可能不会被gzip模块压缩。这是我的代码:importgzipfilename='output.gz'opener=gzip.openiffilename.endswith('.gz')elseopenwithopener(filename,'wb')asfd:print('blahblahblah'.encode(),file=fd)我正在以二进制模式打开可写文件并对要写入的字符串进行编码。但是我收到以下错误:File"/usr/lib/python3.5/gzip.py",line258,inwritedata=memoryview(dat

python - 'utf- 8' codec can' t 解码字节 0xa0 在位置 4276 : invalid start byte

我尝试读取并打印以下文件:txt.tsv(https://www.sec.gov/files/dera/data/financial-statement-and-notes-data-sets/2017q3_notes.zip)根据SEC,数据集以单一编码提供,如下所示:TabDelimitedValue(.txt):utf-8,tab-delimited,\n-terminatedlines,withthefirstlinecontainingthefieldnamesinlowercase.我当前的代码:importcsvwithopen('txt.tsv')astsvfile:r

python - 初学者 Python : Reading and writing to the same file

一周前开始使用Python,我有一些关于读取和写入相同文件的问题要问。我已经在线浏览了一些教程,但我仍然对此感到困惑。我能看懂简单的读写文件。openFile=open("filepath","r")readFile=openFile.read()printreadFileopenFile=open("filepath","a")appendFile=openFile.write("\nTest123")openFile.close()但是,如果我尝试以下操作,我在写入的文本文件中会得到一堆未知文本。任何人都可以解释为什么我会收到这样的错误以及为什么我不能按照下面显示的方式使用相同的o

python - Pandas to_csv : suppress scientific notation in csv file when writing pandas to csv

我正在将pandasdf写入csv。当我将其写入csv文件时,其中一列中的某些元素被错误地转换为科学记数法/数字。例如,col_1中有'104D59'等字符串。字符串在csv文件中主要表示为字符串,因为它们应该如此。但是,偶尔出现的字符串(例如'104E59')会被转换为科学记数法(例如1.04E61)并在随后的csv文件中表示为整数。我正在尝试将csv文件导出到一个软件包中(即pandas->csv->software_new),这种数据类型的变化导致导出出现问题。有没有办法将df写入csv,确保df['problem_col']中的所有元素在生成的csv中都表示为字符串或不转换为科

python - Unicode解码错误: 'utf-8' codec can't decode byte error

我正在尝试从urllib获取响应并对其进行解码为可读格式。文本为希伯来语,还包含{和/等字符首页编码为:#-*-coding:utf-8-*-原始字符串是:b'\xff\xfe{\x00\x00\r\x00\n\x00"\x00i\x00d\x00"\x00\x00:\x00\x00"\x001\x004\x000\x004\x008\x003\x000\x000\x006\x004\x006\x009\x006\x00"\x00,\x00\r\x00\n\x00"\x00t\x00i\x00t\x00l\x00e\x00"\x00\x00:\x00\x00"\x00\xe4\x05\

python - 通过 tqdm.write() 重定向 python 脚本中的打印命令

我在Python中使用tqdm来在我们的脚本中显示控制台进度条。但是,我还必须调用将print消息发送到控制台的函数,而且我无法更改这些函数。通常,在控制台中显示进度条的同时写入控制台会使显示困惑,如下所示:fromtimeimportsleepfromtqdmimporttqdmdefblabla():print"Fooblabla"forkintqdm(range(3)):blabla()sleep(.5)这将创建输出:0%||0/3[00:00Accordingtothedocumentationoftqdmtqdm.write()方法提供了一种在不破坏显示的进度条的情况下将消息

python - 类型错误 : Object of type 'bytes' is not JSON serializable

我刚开始编程Python。我想用scrapy创建一个bot,结果显示类型错误:当我运行项目时,“字节”类型的对象不是JSON可序列化的。importjsonimportcodecsclassW3SchoolPipeline(object):def__init__(self):self.file=codecs.open('w3school_data_utf8.json','wb',encoding='utf-8')defprocess_item(self,item,spider):line=json.dumps(dict(item))+'\n'#printlineself.file.wr

Python Unicode解码错误: 'ascii' codec can't decode byte 0xe2 ordinal not in range(128)

我正在尝试使用Python在GoogleAppEngine中编写我的第一个应用程序(应用程序链接:http://contractpy.appspot.com/-它只是一个实验性应用程序)。整个代码如下。但是,当我提交数据时,出现此错误(显示在日志中):(...)line265,inget"contractType":geted_contractTypeUnicodeDecodeError:'ascii'codeccan'tdecodebyte0xe2inposition949:ordinalnotinrange(128)第265行在这个ifblock中:self.response.ou

C#byte数组获取每一位值

获取byte中每一位的值bytebyData=0x36;intn0,n1,n2,n3,n4,n5,n6,n7;n0=(byData&0x01)==0x01?1:0;n1=(byData&0x02)==0x02?1:0;n2=(byData&0x04)==0x04?1:0;n3=(byData&0x08)==0x08?1:0;n4=(byData&0x10)==0x10?1:0;n5=(byData&0x20)==0x20?1:0;n6=(byData&0x40)==0x40?1:0;n7=(byData&0x80)==0x80?1:0;获取int16中其中某几位的数值bit内容 11-15预留