forked from gkdevops/python-data-engineer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiles_1.py
More file actions
executable file
·28 lines (20 loc) · 731 Bytes
/
files_1.py
File metadata and controls
executable file
·28 lines (20 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 1: Open the file in read mode
with open('example.txt', 'r') as my_data:
content = my_data.read()
print("Current File Content:")
print(content)
# 2: Open the file in Append mode
with open('example.txt', 'a', encoding='utf-8') as data:
data.write('\nAppended line of text.\n')
print('Line appended successfully.')
with open('example.txt', 'r', encoding='utf-8') as data:
content = data.read()
print('\nFile content after appending:')
print(content)
# 3: Modify and overwrite content
with open('example.txt', 'r') as file:
old_content = file.read()
new_content = old_content.lower()
with open('example.txt', 'w') as file:
file.write(new_content)
print("Content converted to lowercase and saved.")