How to edit Text Files with Python | Beginners Tutorial

Опубликовано: 04 Август 2026
на канале: Trying to learn...
249
5

import os

list_files = os.listdir(".")
list_text = [i for i in list_files if i.endswith(".txt")]
print(list_files)
print(list_text)

new_files = ["text.txt", "text2.txt", "text3.txt", "text4.txt"]

for file in new_files:
with open(file, "w"):
pass
with open(file, "r+") as text:
text.write("hello world")
text.seek(0)
print(text.read())

with open("new file") as text:
print(text.txt)