|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- f = open('F:\\record.txt')
- boy = []
- girl = []
- count = 1
- for each_line in f:
- if each_line[:6] != '======':
- (name, content) = each_line.split(':',1)
- if name == '小甲鱼':
- boy.append(content)
- else:
- girl.append(content)
- else:
- boy_file_name = 'boy_' + str(count) + '.txt'
- girl_file_name = 'boy_' + str(count) + '.txt'
- boy_file = open(boy_file_name,'w')
- girl_file = open(girl_file_name,'w')
- boy_file.writelines(boy)
- girl_file.writelines(girl)
- boy_file.close()
- girl_file.close()
- boy = []
- girl = []
- count += 1
-
- f.close()
复制代码
求助,boy_file = open(boy_file_name,'w') 这里如果要指定文件的地址,应该怎么写呢?
girl_file = open(girl_file_name,'w')
- f = open('F:\\record.txt')
- boy = []
- girl = []
- count = 1
- for each_line in f:
- if each_line[:6] != '======':
- (name, content) = each_line.split(':',1)
- if name == '小甲鱼':
- boy.append(content)
- else:
- girl.append(content)
- else:
- boy_file = open(f'F:\\boy_{count}.txt','w')
- girl_file = open(f'F:\\girl_{count}.txt','w')
- boy_file.writelines(boy)
- girl_file.writelines(girl)
- boy_file.close()
- girl_file.close()
- boy = []
- girl = []
- count += 1
-
- f.close()
复制代码
|
|