
Exercise 41
Write a Python program allowing from a given list to create a text file whose lines are the elements of this list. Example if the list is:
List_programming_books = ["Python programming books", "Java programming books", "C ++ programming books", "C # programming books"]
, the generated file will be formed by the lines:
Python programming books
Java programming books
C ++ programming books
C # programming books
Solution
import os
List_programming_books = ["Python programming books", "Java programming books", "C ++ programming books", "C # programming books"]
file = open("List_programming_books.txt" , "w")
for element in List_programming_books:
file.write(element + "n")
file.close()
os.startfile("List_programming_books.txt")
Younes Derfoufi
my-courses.net
my-courses.net