Strange thing: file.close did not show error but work wrong

Emile van Sebille emile at fenx.com
Wed Nov 21 21:25:24 EST 2001


"wqhdebian" <wqhdebian at 263.net> wrote in message
news:db288b61.0111211822.2e903177 at posting.google.com...
> f='d:\\d.txt'
> fdw='d:\\matlabdata.txt'
> import string
> fd=open(f,'r')
> fdw=open(fdw,'w+')
> b=fd.readlines()
> num=len(b)
> print 'num='
> print num
> #print b
> print type(b)
> #a=string.split(b,'  ')
> print len(b)
> #for i in b[:]:
>  # print i
> fdw.write('i')
> fd.close###########################
> fdw.close#########################  When I use like this ,there is no
> warning and
> ##############any error message,but the file do not have been
> writen.After I change back to fdw.close(),Then it work well.
>


Yes, this is all as it should be.

Python simply recognizes the name without error.  In console mode the same
line would have responded as though you had typed in print fdw.close which
would then respond with something like "method close of file object".

HTH,

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list