Skip to content

Instantly share code, notes, and snippets.

@conquistadorjd
Last active March 30, 2019 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conquistadorjd/1ca011391e4824d30798a7535a0aad97 to your computer and use it in GitHub Desktop.
Save conquistadorjd/1ca011391e4824d30798a7535a0aad97 to your computer and use it in GitHub Desktop.
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