|  | 
 
| 
在看老乌龟python入门视频时编写写入文件的代码,但最后运行失败,如图所示。求助大家!(读取的文档和代码在一个文件夹放着)
x
马上注册,结交更多好友,享用更多功能^_^您需要 登录 才可以下载或查看,没有账号?立即注册  代码:
 def save_file(boy,girl,count):
 file_name_boy = 'boy_' + str(count) + '.txt'
 file_name_girl = 'girl_' + str(count) + '.txt'
 
 boy_file = open(file_name_boy, 'w')
 girl_file = open(file_name_girl, 'w')
 
 boy_file.writelines(boy)
 girl_file.writelines(girl)
 
 boy_file.close()
 girl_file.close()
 
 def split_file(file_name):
 f = open('001.txt','r')
 
 boy=[]
 girl=[]
 count=1
 
 for each_line in f:
 if each_line[:4] != '====':
 (role,line_spoken) = each_line.split(':',1)
 if role == '小乌龟':
 boy.append(line_spoken)
 if role == '小客服':
 girl.append(line_spoken)
 
 else:
 save_file(boy,girl,count)
 
 boy = []
 girl = []
 count += 1
 
 save_file(boy,girl,count)
 
 f.close()
 print(end)
 
 split_file('001.txt')
 
 报错:IDLE internal error in runcode()
 Traceback (most recent call last):
 File "D:\新建文件夹 (2)\lib\idlelib\rpc.py", line 339, in putmessage
 r, w, x = select.select([], [self.sock], [])
 TypeError: argument must be an int, or have a fileno() method.
 
 During handling of the above exception, another exception occurred:
 
 Traceback (most recent call last):
 File "D:\新建文件夹 (2)\lib\idlelib\rpc.py", line 240, in asyncqueue
 self.putmessage((seq, request))
 File "D:\新建文件夹 (2)\lib\idlelib\rpc.py", line 342, in putmessage
 raise OSError("socket no longer exists")
 OSError: socket no longer exists
 
这个错误和你的代码没有关系,是idle的内部错误,可能是由于操作系统的问题导致,重启电脑再试一下。 | 
 |