write a list to a file using the writelines 28 29 function

Solutions on MaxInterview for write a list to a file using the writelines 28 29 function by the best coders in the world

showing results for - "write a list to a file using the writelines 28 29 function"
Caterina
09 Feb 2020
1# Program to write multiple lines to text file using writelines() function
2with open("python.txt", "w") as file:
3    content = ["Hello\n", "Welcome to Python Tutorial\n", "Cheers \n" ]
4    file.writelines(content)
5    file.close()
6
7# Program to read the entire file (absolute path) using read() function
8with open("C:/Projects/Tryouts/python.txt", "r") as file:
9    content = file.read()
10    print(content)
11    file.close()