Last active
January 10, 2021 02:56
-
-
Save kang8/2a9f4cf6742f43affdd35fffd3063db8 to your computer and use it in GitHub Desktop.
python 文件读取,并处理文件中的数据
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
------------------------------ | |
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