fichier de lecture python
with open("file.txt", "r") as txt_file:
return txt_file.readlines()
Supermavster
with open("file.txt", "r") as txt_file:
return txt_file.readlines()
txt = open('FILENAME.txt')
txtread = txt.read()
print(txtread)
print(txt.read())
with open('pagehead.section.htm','r') as f:
output = f.read()
my_file = open("C:\\Users\\Python\\file.txt", "r")
#Give the path accurately and use \\
text = my_file.read()
print(text)
#Output: The text in file.txt will be printed
lines = []
with open('the-zen-of-python.txt') as f:
lines = f.readlines()
count = 0
for line in lines:
count += 1
print(f'line {count}: {line}')
Code language: JavaScript (javascript)
# Open function to open the file "MyFile1.txt"
# (same directory) in append mode and
file1 = open("MyFile.txt","a")
# store its reference in the variable file1
# and "MyFile2.txt" in D:\Text in file2
file2 = open(r"D:\Text\MyFile2.txt","w+")