文件内容如下:
##this is the comment
but this is not comment '####', LOL # this is a normal comment
Run Code Online (Sandbox Code Playgroud)
我只是想过滤所有评论并获得过滤后的内容,但我不知道如何避免过滤不是评论的英镑符号.
fileLines = [line.strip() for line in file if '#' != line[0] ]
Run Code Online (Sandbox Code Playgroud)
这段代码只是可以过滤注释符号,这是一行的第一个字符.
我想要的结果就像下面一行:
but this is not comment '####', LOL
Run Code Online (Sandbox Code Playgroud)
import shlex
filelines = [' '.join(shlex.split(line,True)) for line in file]
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅shlex文档.
| 归档时间: |
|
| 查看次数: |
347 次 |
| 最近记录: |