Shaunak Bangale <shaunak.bang...@gmail.com> writes: > ... > while (count > 0): > try : > # read line from file: > print(file.readline()) > # parse > parse_json(file.readline()) > count = count - 1 > except socket.error as e: > print('Connection fail', e) > print(traceback.format_exc()) > ... > Error: > except socket.error as e: > ^ > SyntaxError: invalid syntax
Are you sure, that there is no invisible character at the end of that line? When I try code like the above (in PYthon 2.7), there is no "SyntaxError": >>> while(False): ... try : ... # read line from file: ... print(file.readline()) ... # parse ... parse_json(file.readline()) ... count = count - 1 ... except socket.error as e: ... print('Connection fail', e) ... print(traceback.format_exc()) ... >>> Another reason for your problem could be an older Python version. The "as" construct as part of the "except" clause is a more recent addition to Python. -- https://mail.python.org/mailman/listinfo/python-list