Issue
I have just started writing in python, and the indentation is taking the best of me. I have this code:
import json
if __name__ == '__main__':
is_json('test')
def is_json(str):
try:
json.loads(str)
except ValueError, e:
return False
return True
Which throws:
File "so.py", line 9 except ValueError, e: ^ SyntaxError: invalid syntax
I am using only tabs.
Solution
Your code had two mistakes:
First in the
except
partSecond is that you declared
is_json
at the bottom
If you declare at bottom you may get NameError: name 'is_json' is not defined
error.
import json
def is_json(str):
try:
json.loads(str)
except ValueError as e:
return False
return True
if __name__ == '__main__':
is_json('test')
Answered By - shubham johar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.