E
Eur van Andel
Hi
I tried this:
Traceback (most recent call last):
File "file_try.py", line 19, in ?
logfile.write("T1, T2, T3")
AttributeError: 'str' object has no attribute 'write'
???
This works:
Why can't a function return a file object?
I tried this:
from time import strftime, localtime
def make_logfile():
logfile = open(strftime("%d-%m-%Y_%H-%M.log", localtime()),'w')
logfile.write('temperatures and pump duty cycles\n')
logfile.write('from six fans and pump controller\n')
return(logfile)
logfile = make_logfile
T1 = 20
T2 = 30
T3 = 40
logfile.write("T1, T2, T3") # I know this does not work
Traceback (most recent call last):
File "file_try.py", line 19, in ?
logfile.write("T1, T2, T3")
AttributeError: 'str' object has no attribute 'write'
???
This works:
from time import strftime, localtime
logfile = open(strftime("%d-%m-%Y_%H-%M.log", localtime()),'w')
logfile.write('temperatures and pump duty cycles\n')
logfile.write('from six fans and pump controller\n')
T1 = 20
T2 = 30
T3 = 40
logfile.write("T1, T2, T3")
Why can't a function return a file object?