Exception handling for socket.error in Python 3.5/RStudio
shaunak.bangale at gmail.com
shaunak.bangale at gmail.com
Mon Feb 8 03:04:24 EST 2016
On Sunday, February 7, 2016 at 1:23:32 AM UTC-7, dieter wrote:
> Shaunak Bangale <shaunak.bangale at 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.
Hi Dieter,
I typed that line again but didn't help. I am using Python 3.5.
More information about the Python-list
mailing list