import json
if __name__=='__main__':
try:
with open('input.json','r') as f:
data=json.loads(f.read())
output=",".join([*data[0]])
for obj in data:
output += f'\n{obj["Name"]},{obj["age"]},{obj["birthyear"]}'
with open("output.csv","w") as f:
f.write(output)
except Exception as ex:
print(f'eror:{str(ex)}')
it shows eror:
PS C:\Users\DELL> & C:/Users/DELL/AppData/Local/Programs/Python/Python312/python.exe "c:/Users/DELL/Desktop/python/project/New folder/password generator/main.py"
File "c:\Users\DELL\Desktop\python\project\New folder\password generator\main.py", line 7
output=",".join([*data[0]])
^^^^^^
SyntaxError: expected 'except' or 'finally' block
PS C:\Users\DELL>
I use try except block in my code but why except block can’t run here?
You need to sign in to view this answers
Leave feedback about this