I'm for help.

How to create 10 copies of a file in Python? My code does not work:

a=open("D:\\python21\\long.txt","r") b=open("D:\\python21\\str(i).txt","w") for i in range(11): b.write(a.read()) a.close() b.close() 

Closed due to the fact that off-topic participants Enikeyschik , Sergey Gornostaev , Kir_Antipov , Xander , freim 24 Apr at 10:41 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is closed, as it is customary to ask questions in Russian only on Russian in Stack Overflow . Please translate your question into Russian or use Stack Overflow in English ." - Enikeyschik, Sergey Gornostaev, Kir_Antipov, Xander, freim
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 2
    Translate, please, your question into Russian. - strawdog 8:17 pm
  • one
    Translator's note, that is me. Judging by the attempts in the code, you still need 10 files, and not 10 copies of one file in another, as is done with @S. Nick - Sergey Nudnov
  • @SergeyNudnov is a bad translator because of me :) - S. Nick
  • one
    @ S.Nick It is easier for me, like all Belarusians. We speak Russian, Ukrainian, Polish and more, we understand. :) - Sergey Nudnov 9:22 pm
  • Note the name of your source file: long.txt. This suggests that it’s a bad idea to read it into memory and then write it back to disk - just to copy. If its size, for example, 4GB, it will be oh. So the answer @extrn the most optimal. - Sergey Nudnov

1 answer 1

 from shutil import copyfile for i in range(1, 11): copyfile(r'D:\python21\long.txt', rf'D:\python21\str({i}).txt')