嗨,我是python的新成员(我已经学了3天了),感谢您的帮助。在
所以我做了这个函数,你看下面,创建了2.txt文件,叫做oldfile,newfile。在旧文件中我写了64个字符(比如“asasdasffafdsfgsgsdgs”)。这个函数应该打开两个文件并从新文件中写入50个字符,但是当我在pyscripter中按start时,代码可以工作,但是它什么也不做(它不会向新文件.txt). 在
def copy_file(oldfile, newfile):
infile = open(oldfile, 'r')
outfile = open(newfile, 'w')
while True:
text = infile.read(50)
if text == "":
break
outfile.write(text)
infile.close()
outfile.close()
return
您需要调用函数:
相关问题 更多 >
编程相关推荐