June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,7 +1,10 @@
|
|||
>>> marker, line = '#', 'apples, pears # and bananas'
|
||||
>>> line[:line.index(marker)].strip()
|
||||
'apples, pears'
|
||||
>>>
|
||||
>>> marker, line = ';', ' apples, pears ; and bananas'
|
||||
>>> line[:line.index(marker)].strip()
|
||||
'apples, pears'
|
||||
def remove_comments(line, sep):
|
||||
for s in sep:
|
||||
i = line.find(s)
|
||||
if i >= 0:
|
||||
line = line[:i]
|
||||
return line.strip()
|
||||
|
||||
# test
|
||||
print remove_comments('apples ; pears # and bananas', ';#')
|
||||
print remove_comments('apples ; pears # and bananas', '!')
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
def remove_comments(line, sep):
|
||||
for s in sep:
|
||||
line = line.split(s)[0]
|
||||
return line.strip()
|
||||
import re
|
||||
|
||||
# test
|
||||
print remove_comments('apples ; pears # and bananas', ';#')
|
||||
print remove_comments('apples ; pears # and bananas', '!')
|
||||
m = re.match(r'^([^#]*)#(.*)$', line)
|
||||
if m: # The line contains a hash / comment
|
||||
line = m.group(1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue