[newbie] file object not returned by function?
Eur van Andel
eur at fiwihex.nl
Fri Oct 31 06:44:58 EST 2003
Hi
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?
--
Ir. E.E. van Andel, Fine Wire Heat Exchangers, Fiwihex B.V. www.fiwihex.com
Wierdensestraat 74, NL-7604 BK Almelo, The Netherlands eur at fiwihex.nl
phone +31-546-491106 fax +31-546-491107 mobile +31-653-286573
More information about the Python-list
mailing list