初学python到读写这部分,遇到了不懂的地方,在复制文本内容时,file.read()出现两遍后复制的文本a1.txt就没有内容了,
我的想法是file.read()是把文本内容读出来啊,语法也没报错,不清楚什么原因,麻烦解惑
用一个变量记录读取的内容,再写入
s = file.read()
file1.write(s)
或者直接
file1.write( file.read())
你那么写,等于调用了2次read
待读取的文件:demo.txt
A thread is a basic unit of CPU execution. It must depend on the process surviving. A thread is an execution context, which is what a CPU needs to execute
A list of instructions. In Python, multithreading takes longer.
假设我们只希望读取30字节的数据:
data = open("demo.txt", "r").read(30)
print(data)
执行结果如下:
A thread is a basic unit of CP