Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python Utilities
one,two,three,four,
################################################################################################
# name: list_to_file_01.py
# desc:
# date: 2019-03-30
# Author: conquistadorjd
################################################################################################
print('*** Program Started ***')
score = ["one","two","three", "four"]
with open("list_to_file.txt", "w") as f_write:
for s in score:
f_write.write(str(s) +",")
with open("list_to_file.txt", "r") as f_read:
lines = f_read.read().split(',')
print('lines : ', lines )
print('type of lines : ', type(lines) )
for line in lines:
print("line : ", line)
print('*** Program Completed ***')
################################################################################################
# name: list_to_file_02.py
# desc:
# date: 2019-03-30
# Author: conquistadorjd
################################################################################################
print('*** Program Started ***')
score = ["one","two","three", "four"]
f_write = open("list_to_file.txt", "w")
for s in score:
f_write.write(str(s) +",")
# Expkicite close is needed in this case
f_write.close()
f_read = open("list_to_file.txt", "r")
lines = f_read.read().split(',')
print('lines : ', lines )
print('type of lines : ', type(lines) )
for line in lines:
print("line : ", line)
## This close can be ommited considering program termination closes all open files.
f_read.close()
print('*** Program Completed ***')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment