我正在尝试确定文件可能使用的注释字符。例如:
site,rank
#alexa.com/rankings
google.com,1
yahoo.com,2有没有办法在列表中获得最多的注释"startswith“路径,并将其与一组可能的注释字符相交?我现在做的事情如下,但看起来很幼稚:
POSSIBLE_COMMENT_CHARS = ['#', '//', '/*', '*/']
def get_comment_char(file):
with open(file) as f:
for line in f:
for _char in POSSIBLE_COMMENT_CHARS:
if line.startswith(_char):
return _char对于上面的文件数据,它将返回:
get_comment_char(myalexafile)
>>> #https://stackoverflow.com/questions/53840655
复制相似问题