-2

I have a file lets say "Mrinq_Parts_Available.txt" which looks like this.

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

I have a python code which does split of those lines.

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)

But the output is shown like this:

[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']

How do I remove the 'b' preceding each parsed data?

Shubham Kuse
  • 135
  • 1
  • 2
  • 10
  • Another similar question: https://stackoverflow.com/q/6269765/3160529 – Shubham May 02 '18 at 09:56
  • You open your file as binary with `'b'` inside `open()` function. Simply open file as standard by removing `b`: `with open(inputFile, 'r') as f:` – Algorys May 02 '18 at 09:56

1 Answers1

0

Your file is clearly an ASCII file, so you should open it as an ASCII :

with open(inputFile, 'r') as f:
Kefeng91
  • 802
  • 6
  • 10