python - How to comment out one line of a multiline statement -
as shown in following code, groupby
line should commented out:
lines = fileinput.input(fin) \ | take(300) \ | where(lambda x: not x.strip().endswith(',,,,,')) \ \ # | groupby(lambda x: x[42]) | teefile(fout,100)
however above syntax - , several variations on - not work:
\ # | groupby(lambda x: x[42]) ^ syntaxerror: unexpected character after line continuation character
another variation attempted:
# | groupby(lambda x: x[42]) \
is there way comment out portion of longer statement requiring continuation characters? or out of luck - along lines of python's inability (/unwillingness) support inline comments?
i on 2.7
update here small update code snippet make self contained.
import sys, pipe, fileinput ; pipe import *; lines = fileinput.input(fin) \ | take(300) \ | where(lambda x: not x.strip().endswith(',,,,,,,,')) \ # | groupby(lambda x: x[42]) \ | tee
it including import now. different errors in ipython
vs intellij
:
ipython
:
file "<ipython-input-2-60c5dbee382d>", line 3 | tee ^ indentationerror: unexpected indent
intellij
:
file "<ipython-input-30-1f7b64578a1f>", line 16 lines = fileinput.input(fin) | take(300) | where(lambda x: not x.strip().endswith(',,,,,,,,,,,,,,,,,,,,,')) \ # | groupby(lambda x: x[42]) ^ syntaxerror: unexpected character after line continuation character
use implicit line continuation parentheses:
lines = (fileinput.input(fin) | take(300) | where(lambda x: not x.strip().endswith(',,,,,')) # | groupby(lambda x: x[42]) | teefile(fout,100))
inside unclosed parentheses (
, brackets [
, or braces {
, python perform line continuation automatically, across lines comments. rules line joining backslashes don't allow line continuation on line comment.
Comments
Post a Comment