xxxxxxxxxx
<?php
$file = fopen("welcome.txt","r")or exit("unable to open file!");
while(!feof($file)){
echo fgets($file)."<br>";
}
fclose($file);
?>
xxxxxxxxxx
with open("file.txt") as file_in:
lines = []
for line in file_in:
lines.append(line)
xxxxxxxxxx
# Using readlines()
file1 = open('myfile.txt', 'r')
Lines = file1.readlines()
xxxxxxxxxx
>>> f = open('workfile', 'w', encoding="utf-8")
>>> f.readline()
'This is the first line of the file.\n'
>>> f.readline()
'Second line of the file\n'
>>> f.readline()
''
xxxxxxxxxx
# Question: Which function is used to read single line from file?
# Answer: readline()