Untitled
unknown
python
2 years ago
870 B
17
Indexable
import re
file1 = open('newtname.txt', 'r')
Lines = file1.readlines()
vendors = []
# Strips the newline character
for line in Lines:
col1 = line[0:8]
col2 = line[8:29]
vendor = {
"id": "",
"name": "",
"addrLine": [],
"fullAddress": ""
}
x = re.search("[A-Z][0-9]{6}", col1)
if (x):
vendor['id'] = x.group(0)
vendor['name'] = col2.strip()
vendors.append(vendor)
else:
tmp = col2.strip()
if (len(vendors) > 0 and len(tmp) > 0 and not '--' in tmp and not 'newt' in tmp):
vendor = vendors.pop()
vendor['addrLine'].append(tmp)
vendors.append(vendor)
for v in vendors:
str = ' '.join(v['addrLine'])
v['fullAddress'] = str
print(f"{v['id']};{v['name']};{v['fullAddress']}")Editor is loading...