N
Neil Cerutti
I installed Python 3.1 today, and I've been porting my small
library of programs to the new system.
I happened to read the interesting "Idioms and Anti-Idioms"
HOWTO, and saw the '\' continuation character labeled an
anti-idiom. I already generally avoided it, so I just nodded.
Unfortunately, the new "nested" with statement (which I also read
about today) forces me into this anti-idiom. When replacing an
appearance of contextlib.nested with the 3K with statement, I
ended up with an unexpected syntax error.
with (open(roster_path, 'r') as roster_file,
open(disb_path, 'w') as out_file,
open(report_path, 'w') as report_file):
The result was:
File "C:\project\codxml.py", line 184
with (open(roster_path, 'r') as roster_file,
^
SyntaxError: invalid syntax
Unless I'm missing something, I have to subject my code to a bit
of contintuation:
with open(roster_path, 'r') as roster_file,\
open(disb_path, 'w') as out_file,\
open(report_path, 'w') as report_file:
I was thinking about submitting a enhancement request to the
HOWTO, explaining that continuation my be required in this
context. Am I missing anything obvious?
library of programs to the new system.
I happened to read the interesting "Idioms and Anti-Idioms"
HOWTO, and saw the '\' continuation character labeled an
anti-idiom. I already generally avoided it, so I just nodded.
Unfortunately, the new "nested" with statement (which I also read
about today) forces me into this anti-idiom. When replacing an
appearance of contextlib.nested with the 3K with statement, I
ended up with an unexpected syntax error.
with (open(roster_path, 'r') as roster_file,
open(disb_path, 'w') as out_file,
open(report_path, 'w') as report_file):
The result was:
File "C:\project\codxml.py", line 184
with (open(roster_path, 'r') as roster_file,
^
SyntaxError: invalid syntax
Unless I'm missing something, I have to subject my code to a bit
of contintuation:
with open(roster_path, 'r') as roster_file,\
open(disb_path, 'w') as out_file,\
open(report_path, 'w') as report_file:
I was thinking about submitting a enhancement request to the
HOWTO, explaining that continuation my be required in this
context. Am I missing anything obvious?