Python Forum

Full Version: a solo \ at end of comment
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
what happens if there is a solo backslash at the end of a line in a comment?
   x = 92 # the power char is a \
Nothing everything after # is ignored.
If take a deeper look tokenize.py line 113 114.
So can do a test.
>>> import re
>>> 
>>> s = 'Hello World'
>>> r = re.search(r'#[^\r\n]*', s) 
>>> repr(r)
'None'

>>> s = 'Hello# World'
>>> s = 'Hello# World'
>>> r = re.search(r'#[^\r\n]*', s)
>>> r
<re.Match object; span=(5, 12), match='# World'>
>>> r.group()
'# World'

# No matter where put # the rest will match
>>> s = 'Hello W#orld'
>>> r = re.search(r'#[^\r\n]*', s)
>>> r.group()
'#orld'
So line 113 regex Comment = r'#[^\r\n]*',match all after # to carriage return or new line.
line 114 give a hint what Tokenization should do with it Ignore.
that code block won't scroll for me. so i can't see 113 or 114. oh wait, your 1 key must be bouncy.

i was wondering if the \ at the end of the line would continue that line onto the next.