为什么复制文本无内容(语言-python)

初学python到读写这部分,遇到了不懂的地方,在复制文本内容时,file.read()出现两遍后复制的文本a1.txt就没有内容了,
我的想法是file.read()是把文本内容读出来啊,语法也没报错,不清楚什么原因,麻烦解惑

img

用一个变量记录读取的内容,再写入
s = file.read()
file1.write(s)
或者直接
file1.write( file.read())
你那么写,等于调用了2次read

  • 你可以参考下这个问题的回答, 看看是否对你有帮助, 链接: https://ask.csdn.net/questions/1052495
  • 你也可以参考下这篇文章:Python 读取txt文本总结:read()、readlines()并去掉\n
  • 除此之外, 这篇博客: Python file read方法:读取文件中的 2. 指定字节数读取文件 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 待读取的文件: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