On Feb 4, 2005, at 06:39, Chad Crabtree wrote:

I've tried this and I cannot figure out why this does not work.  I
figure this has something to do with order of operations.  I figured
someone would know exactly why it doesn't work.  Wouldn't this start
inside parens then from left to right?

open(item,'w').write(open(item,'r').read().replace(' ',''))

I tried this on the shell just trying to do some quick text
replacement
because I could figure out how to get awk to do it, and I didn't want
to
spend 5 hours RTFM.  I got it to work by breaking it up to several
statements, but I would like to know.

It's quite easy: evaluation starts from left to right. The program opens item for writing (thus deleting it), creating a file object, then executes its write method on the argument in the parens. However, since at that point item is now empty, there is nothing to read from.


-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting and sweating as you run through my corridors... How can you challenge a perfect, immortal machine?"


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to