(Oct-10-2022, 07:58 AM)rob101 Wrote:(Oct-10-2022, 03:55 AM)Calli Wrote: It looks like it's printing out the last line of the file
(Oct-10-2022, 07:06 AM)ibreeden Wrote: Is'nt that what you wanted? You want more? Then add 4 spaces before the print function.
Indeed: move theprint()
function into thefor
loop.
Traceback (most recent call last): File "/media/redhat/test/data/df.py", line 15, in <module> print(amount,email,mobile,accountOwner) NameError: name 'amount' is not defined
with open ('df.json', 'r') as f: content = f.read() temp = content.split(',') for item in temp: if 'amount' in item: amount = item.strip() elif 'email' in item: email = item.strip() elif 'mobile' in item: mobile = item.strip() elif 'accountOwner' in item: accountOwner = item.strip() print(amount,email,mobile,accountOwner)