Answer the question
In order to leave comments, you need to log in
How to pull the file with the maximum number?
Task: there is a folder with text data .txt, where all the names are ordered like: "1.txt", "2.txt", "3.txt" .... "15.txt", "16.txt" and so on .d. How to take a file with the last (maximum) number and create a file with the next number and work with it already. For example, if the maximum is "25.txt", then you need to create "26.txt" and work with it already. How to implement this in Python with open()
Answer the question
In order to leave comments, you need to log in
from pathlib import Path
max_id = max(int(path.stem) for path in Path('path_to_folder').glob('*.txt'))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question