Python & Linux, some questions (2)

Peter Hansen peter at engcorp.com
Tue Mar 16 15:38:44 EST 2004


Luca T. wrote:

> Ok...
> Now...
> I made this simple program as a test:
> 
> import popen2
> r,w,e = popen2.popen3('su -c ls')
> for line in e.readlines():
>     print 'E: ' + line
> for line in r.readlines():
>     print 'R: ' + line
> 
> r.close
> w.close
> e.close

Bug: you are referencing r.close and friends, but not actually calling 
them.  Python is not VB (or Pascal, etc), so you *must* include the 
parentheses to make a method call:

r.close()
w.close()
e.close()

PyChecker can warn about such things, and many others.

-Peter



More information about the Python-list mailing list