I have a problem by reading my .txt file and save it in dict. This is my following code:
def __init__(self, folder_path):
os.chdir(folder_path)
self._path = folder_path
self._data = {}
_files = glob.glob('*.txt')
_temp = {}
for dat in _files:
_temp.clear()
with open(dat,"r",encoding="utf-8") as f:
for item in f:
if item != '\n':
custom = (item.strip('\n').split('='))
_temp[custom[0]] = custom[1]
self._data[dat] = _temp
print(self._data)
And this is the output:
{'RC0603FR-07100KL.txt': {'count': '20', 'value': 'TPS73033', 'package': 'SOT-23-5'},
'RC0805FR-07100KL.txt': {'count': '20', 'value': 'TPS73033', 'package': 'SOT-23-5'},
'TPS73033DBVT.txt': {'count': '20', 'value': 'TPS73033', 'package': 'SOT-23-5'}}
The exactly problem is, that the last value override the all other one. For ex. this is how it should look like:
{'RC0603FR-07100KL.txt': {'count': '100', 'value': '100k', 'package': 'Chip'},
'RC0805FR-07100KL.txt': {'count': '50', 'value': '10n', 'package': 'Cap'},
'TPS73033DBVT.txt': {'count': '20', 'value': 'TPS73033', 'package': 'SOT-23-5'}}
What I'm doing wrong?
A sample of .txt file:
count=50
value=100k
unit=Ohm
package=0603
description=Chip Resistor
supplier=Digikey
supplierpartnumber=311-100KHRCT-ND
price=0.009
currency=CHF