Last active
January 21, 2019 03:51
-
-
Save su27/a3bd23f82ed85e9c07f5e89912f4296c to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python | |
def main(): | |
f = open('game_log.tsv', encoding='utf-8') | |
wf = open('game_log_new.csv', 'w', encoding='utf-8') | |
for i, l in enumerate(f.readlines()): | |
if i == 0: | |
wf.write('event_time,event_lat,event_lng,tracker_trigger,comments\n') | |
else: | |
l = l.replace('None', '') | |
data = l.strip().split('\t') | |
data[0] = data[0].replace(' ', '-', 1) | |
wf.write('%s\n' % ','.join(data)) | |
wf.close() | |
f.close() | |
if __name__ == '__main__': | |
main() |
wf.close
完了之后是不是 f.close()
也应该有?
windows 下有默认编码的问题, 我加了编码:
#!/usr/bin/env python
def main():
f = open('game_log.tsv',encoding='utf-8')
wf = open('game_log_new.csv', 'w', encoding='utf-8')
for i, l in enumerate(f.readlines()):
if i == 0:
wf.write('event_time,event_lat,event_lng,tracker_trigger,comments\n')
else:
l = l.replace('None', '')
data = l.strip().split('\t')
data[0] = data[0].replace(' ', '-', 1)
wf.write('%s\n' % ','.join(data))
wf.close()
f.close()
if __name__ == '__main__':
main()
感谢大爷的反馈.
@LeoQuote 竟然有编码问题,没试Windows,捂脸。。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
下载这个脚本,放在解压后的
game_log.tsv
同一目录下,然后执行:会生成一个新文件
game_log_new.csv