Python membaca baris file demi baris
with open("file.txt") as file_in:
lines = []
for line in file_in:
lines.append(line)
Caleb McNevin
with open("file.txt") as file_in:
lines = []
for line in file_in:
lines.append(line)
#there are many modes you can open files in. r means read.
file = open('C:\Users\yourname\files\file.txt','r')
text = file.read()
#you can write a string to it, too!
file = open('C:\Users\yourname\files\file.txt','w')
file.write('This is a typical string')
#don't forget to close it afterwards!
file.close()
with open('pagehead.section.htm','r') as f:
output = f.read()
fin = open("NAME.txt", 'r')
body = fin.read().split("\n")
line = fin.readline().strip()
# 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+")
spv = open("example.txt", "r")
print(spv.red())
# r, is to make the file readable but you can have more like: a - w - x - t - b