file = open("filehandling_ex.txt",'w+')
temperatures=[10,-20,-289,100]
def c_to_ff(c):
if c < -273.15:
return "Cannot write. " + str(c) + " is under -273.15"
else:
f = c*9/5 + 32 # celisus to farenheit
return f
for temp in temperatures:
result = str(c_to_ff(temp))+"\n"
file.write(result)
print(c_to_ff(temp))
file.close()
# close 없이 쓰려면 with open 사용
with open("filehandling_ex.txt", 'a+') as file:
file.seek(0)
content = file.read()
file.write("\nAWESOME !")
Python def 1
기억상실 보존용
Python def 1
python list 1
####
file = open("f_fruits.txt", 'r')
content = file.readlines()
print(content)
for i in content:
print(len(i.strip())) # list를 벗겨내기
file.close()
print("\n\n")
####
#####
file = open("fs_fruits.txt", 'r')
content = file.readlines()
print (content)
file.close()
print (type(content))
words = ''.join(content) # list를 문자열로
print (type(words))
print (content)
content_each = words.split(', ')
print(content_each)
file = open("fs_fruit_save.txt",'w')
for item in content_each:
file.write(item+"\n")
file.close()
Python List 기본.
치매 예방용 1