Oct-10-2022, 09:54 AM
(This post was last modified: Oct-10-2022, 09:54 AM by rob101.
Edit Reason: code update: now reads one line in to memory
)
Maybe this?
with open ('data', 'r', ) as f: content = 'start' while content: content = f.readline() temp = content.split(',') amount = email = mobile = accountOwner = '' for item in temp: if 'amount' in item: amount = item elif 'email' in item: email = item elif 'mobile' in item: mobile = item elif 'accountOwner' in item: accountOwner = item if amount and email and mobile and accountOwner: print(f"{amount} {email} {mobile} {accountOwner}") amount = email = mobile = accountOwner = ''
Output:"amount":300 "email":"[email protected]" "mobile":"100000012457" "accountOwner":"Tom Hank"
"amount":500 "email":"[email protected]" "mobile":"7845147210" "accountOwner":"Cotton Kate"
"amount":300 "email":"[email protected]" "mobile":"1457845478" "accountOwner":"Stefen James"
"amount":100 "email":"[email protected]" "mobile":"1457812014" "accountOwner":"Michel"
"amount":100 "email":"[email protected]" "mobile":"4578412457" "accountOwner":"Tom Willims"
Sig:
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein