Last active
March 30, 2019 03:06
-
-
Save conquistadorjd/1ca011391e4824d30798a7535a0aad97 to your computer and use it in GitHub Desktop.
Python Utilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Python utilities |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
one,two,three,four, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################################ | |
# 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 ***') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################################ | |
# 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