ТАК, каждый раз, когда я запускаю сценарий, он должен генерировать новый файл журнала.
Например:< /p>
файл_журнала
файл_журнала1
файл_журнала2
.
.
.
.
Код: Выделить всё
def log(message):
try:
counter = 1
# Format the log message with current date and time
log_message = f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] {message}\n"
# Write the message to the log file
with open("log_file.txt", "a") as log_file:
log_file.write(log_message)
except Exception as e:
print(f"Error occurred while logging: {e}")
Подробнее здесь: https://stackoverflow.com/questions/783 ... g-txt-file