def process_file():
with open("data.txt", 'r') as file:
data = file.readlines()
line_count = len(data)
print(f"The Total Number Of lines Are: {line_count}")
error_lines = [line for line in data if 'error' in line.lower()]
for line in error_lines:
print(line.strip())
with open("errors.log", 'w') as log_file:
log_file.writelines(error_lines)
from datetime import datetime as time
def journal_entery():
entry = input("Enter Your Journal Entry: ")
timestamp = time.now().strftime('%Y-%m-%d %H:%M-%S')
entry_with_timestamp = f"{timestamp} -{entry}"
"\n"
try:
with open('journal.txt','a') as journalfile:
journalfile.write(entry_with_timestamp)
print('Entry added to data.txt')
except Exception as err:
print(f'{err} Occurred')
def numder_sum():
try:
with open('numbers.txt','r') as file:
numbers = file.readlines()
total = 0
for line in numbers:
try:
total += int(line.strip())
except ValueError:
print(f'skipping non-integer value: {line.strip()}')
print(f'sum of integers in numbers.txt: {total}')
except FileNotFoundError:
print('Error: numbers.txt file not found')