Answers for "python store text file in list"

2

how to put a text file into a list python

# name.txt
david
mary
john


with open('names.txt', 'r') as f:
    myNames = [line.strip() for line in f]
    
# Result

['david','mary','john']
Posted by: Guest on December-08-2020
1

list to text file python

with open('your_file.txt', 'w') as f:
    for item in my_list:
        f.write("%sn" % item)
Posted by: Guest on January-05-2021
1

python write list to text file

a_list = ["abc", "def", "ghi"]
f = open("a_file.txt", "w")
for item in a_list:
   f.write(item + "n")
f.close()
Posted by: Guest on May-28-2021

Code answers related to "python store text file in list"

Python Answers by Framework

Browse Popular Code Answers by Language