我有一个文件可以说" Mrinq_Parts_Available.txt"看起来像这样。
Source Date Category SubCategory Present Description Value Units Vendor Part No Package Box Name Location Quantity Ordered Used MOQ=1 MOQ=100 MOQ=1000 Comments Link
Digikey 29-May-15 RF Amplifier No 0.5 W RFMD RFPA3807 SOIC8 10 0 3.4 5V http://www.digikey.com/product-detail/en/RFPA3807TR13/689-1073-1-ND/2567207
我有一个python代码可以拆分这些行。
def removeEmptyLines(inputFile):
with open(inputFile, 'rb') as f:
d = f.readlines()
k = []
for i in d:
k.append(i.split())
print (k)
if __name__=="__main__":
parts_database_file = "Mrinq_Parts_Available.txt"
removeEmptyLines(parts_database_file)
但是输出显示如下:
[b'Source', b'Date', b'Category', b'SubCategory', b'Present', b'Description', b'Value', b'Units', b'Vendor', b'Part', b'No', b'Package', b'Box', b'Name', b'Location', b'Quantity', b'Ordered', b'Used', b'MOQ=1', b'MOQ=100', b'MOQ=1000', b'Comments', b'Link']
[b'Digikey', b'29-May-15', b'RF', b'Amplifier', b'No', b'0.5', b'W', b'RFMD', b'RFPA3807', b'SOIC8', b'10', b'0', b'3.4', b'5V', b'http://www.digikey.com/product-detail/en/RFPA3807TR13/689-1073-1-ND/2567207']
如何删除' b'在每个解析数据之前?
答案 0 :(得分:0)
您的文件显然是ASCII文件,因此您应该以ASCII格式打开它:
with open(inputFile, 'r') as f: