Skip to content

Instantly share code, notes, and snippets.

@kang8
Last active January 10, 2021 02:56
Show Gist options
  • Save kang8/2a9f4cf6742f43affdd35fffd3063db8 to your computer and use it in GitHub Desktop.
Save kang8/2a9f4cf6742f43affdd35fffd3063db8 to your computer and use it in GitHub Desktop.
python 文件读取,并处理文件中的数据
"""
------------------------------
topic_id: 207
sort: monday
------------------------------
topic_id: 444
sort: tuesday
------------------------------
"""
topic_id = None
sort = None
monday = []
tuesday = []
for file_name in range(25):
f = open('./assest/%d.log' % file_name, 'r', encoding='utf-8')
for i in f.readlines():
temp = i.split(':',1)
if (temp[0] == 'topic_id'):
topic_id = temp[1].strip()
elif (temp[0] == 'sort'):
sort = temp[1].strip()
if (sort == 'monday'):
monday.append('%s-%s' % (file_name, topic_id))
elif (sort == 'tuesday'):
tuesday.append('%s-%s' % (file_name, topic_id))
f.close() # don't forget!!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment