[Tutor] Pipe variable to external command (solved)
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Mon May 16 00:29:03 CEST 2005
> Here is what the code I settled on looks like:
>
> ###
> working = email.message_from_file(open(emailfile))
>
> clamav = popen2.Popen3(clamav_cmd,1)
> clamav.tochild.write(working.as_string())
> clamav.tochild.close()
> clamav_result = clamav.fromchild.read().lstrip('stream: ')
> clamav.fromchild.close
^^^^^^^^^^^^^^^^^^^^^^
Hi Jeffrey,
Careful: you may need parens there on your 'close' line. (clothesline?
*grin*)
As written, that last statement doesn't fire off the close() method.
This might be suprising because some other languages make parens optional.
But we need them in Python because Python makes it very easy to get
function references:
######
>>> def calculatePi():
... return 22/7
...
>>> calculatePi
<function calculatePi at 0x402dae64>
######
Without parens, we just get the function reference. We still need to
"call" that function value by using parens, which trigger the function to
fire off:
######
>>> calculatePi()
3
######
Otherwise, your program looks good! I'm glad that it's working for you
now.
Best of wishes!
More information about the Tutor
mailing list