How to read and write multiple files?

后端 未结 8 1155
南方客
南方客 2020-12-24 00:52

I want to write a program for this: In a folder I have n number of files; first read one file and perform some operation then store result in a separate file. Then

8条回答
  •  梦毁少年i
    2020-12-24 01:24

    This thing also works for reading multiple files, my file name is fedaralist_1.txt and federalist_2.txt and like this, I have 84 files till fedaralist_84.txt

    And I'm reading the files as f.

    for file in filename:
            with open(f'federalist_{file}.txt','r') as f:
                 f.read()
    

提交回复
热议问题