CBS U3-Ap
CBS U3-Ap
asyncio.run(read_file())
def read_and_process(filename):
with open(filename, 'r') as f:
return f.read().count("ERROR")
files = os.listdir('logs')
with ThreadPoolExecutor() as executor:
results = executor.map(read_and_process, files)
key = Fernet.generate_key()
f = Fernet(key)
def clean_logs():
for file in os.listdir('logs'):
if file.endswith('.log'):
os.remove(os.path.join('logs', file))
schedule.every().day.at("23:00").do(clean_logs)
while True:
schedule.run_pending()
time.sleep(60)
Rollback on failure:
Advanced Python: Beyond-the-Syllabus - File Handling & Exceptions
import shutil
try:
shutil.copy('important.txt', 'backup.txt')
raise ValueError("Something went wrong")
except Exception:
shutil.copy('backup.txt', 'important.txt')