I would like to ask you about the order in which Python folders are written.
If you run the following sample, you will see
If you look at the written file, you can see
(The top tier is 01.txt02.txt
We are testing with 03.txt04.txt in the 00 folder structure.)
It will be
If you look at the print statement, the order of processing is as follows.
What causes the order to change?
I am a beginner in the program, so I cannot find a solution.
I look forward to your kind cooperation.
It is easy to understand if you keep in mind that the files are buffered.
Buffering is stored in memory before writing to a file, and when a certain amount is accumulated or the file is closed, it is written to a file.
This time, it is recursive, so the output of the recursive is written first.
It is written in the order of buffer 2 and buffer 1, so the results are as described.
One way to get rid of this is to use flush.
However, I think it would be easier to use walk instead of opening the file every time.
Once you open the file, you can use the same file handler to write it down.
© 2022 OneMinuteCode. All rights reserved.