Skip to content

Instantly share code, notes, and snippets.

@lhsfcboy
Created June 26, 2017 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lhsfcboy/ef74bb6a0425c452b92e76af4d01a07e to your computer and use it in GitHub Desktop.
Save lhsfcboy/ef74bb6a0425c452b92e76af4d01a07e to your computer and use it in GitHub Desktop.
同时打开两个文件
with open('name_age.txt', 'r') as fread, open('age_name.txt', 'w') as fwrite:
line = fread.readline()
while line:
name, age = line.rstrip().split(',')
fwrite.write('{},{}\n'.format(age, name))
line = fread.readline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment