I am trying to determine what comment character a file may be using. For example:
site,rank
#alexa.com/rankings
google.com,1
yahoo.com,2
Is there a way to get the most comment "startswith" path in a list, and intersect that with a set of possible comment characters? What I'm doing now is the following, but it seems quite naive:
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
With the above file data it would return:
get_comment_char(myalexafile)
>>> #