Issue
I want to read a notepad file by using the readlines() method.
f = open('/home/user/Desktop/my_file', 'r')
print(f.readlines())
Output
['Hello!\n', 'Welcome to Barbara restaurant. \n', 'Here is the menu. \n']
I don't want the output to include linebreaks.
Note: I want to use the readlines() method.
Note: My operating system is Linux Ubuntu and here's the link to my file.
Expected Output
Hello!
Welcome to Barbara restaurant.
Here is the menu.
Solution
Update (Since you need the readlines() method)
f = open('/home/user/Desktop/my_file', 'r')
for line in f.readlines():
print(line, end='')
Output
Hello!
Welcome to Barbara restaurant.
Here is the menu.
Original
You can read then split each line
f = open('/home/user/Desktop/my_file', 'r')
print(f.read().splitlines())
Output
['Hello!', 'Welcome to Barbara restaurant. ', 'Here is the menu. ']
Answered By - xFranko Answer Checked By - Candace Johnson (WPSolving Volunteer)