[Tutor] Re: This Deletes All my Files
Chad Crabtree
flaxeater at yahoo.com
Fri Feb 4 19:22:14 CET 2005
Thank you all for answering my question. I thought it would be some
misunderstanding on my part. The example Andrei made was very
telling.
Andrei wrote:
>>>>s = "d:/tests/test.txt"
>>>>class dummyfile(object):
>>>>
>>>>
>... def open(self, *args):
>... print "dummyfile.open:", args
>... def write(self, *args):
>... print "dummyfile.write:", args
>... def read(self, *args):
>... print "dummyfile.read:", args
>... return ""
>
>
>>>>def dummyopen(filename, type):
>>>>
>>>>
>... print "dummyopen:", filename, type
>... d = dummyfile()
>... d.open(filename, type)
>... return d
>
>
>
>>>>dummyopen(s, 'w').write(dummyopen(s, 'r').read())
>>>>
>>>>
>dummyopen: d:/tests/test.txt w
>dummyfile.open: ('d:/tests/test.txt', 'w') <--- first open for
writing
>dummyopen: d:/tests/test.txt r
>dummyfile.open: ('d:/tests/test.txt', 'r') <--- then for reading
>dummyfile.read: ()
>dummyfile.write: ('',)
>
>
>
>>spend 5 hours RTFM. I got it to work by breaking it up to several
>>statements, but I would like to know.
>>
>>
>
>And that's the way you *should* write it - code like this doesn't
deserve to
>work anyway :).
>
>Yours,
>
>Andrei
>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>
>
__________________________________
Do you Yahoo!?
The all-new My Yahoo! - Get yours free!
http://my.yahoo.com
More information about the Tutor
mailing list