在Python中,我刚刚从文本文件中读取了一行,我想知道如何编写代码来忽略行开头带有哈希#的注释。
我认为应该是这样的:
for
if line !contain #
then ...process line
else end for loop
但我是Python新手,不知道语法
您可以使用以。。开始() http://docs.python.org/library/stdtypes.html#str.startswith
eg
for line in open("file"):
li=line.strip()
if not li.startswith("#"):
print line.rstrip()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)