[Tutor] assigning a variable

Karl Pflästerer sigurd at 12move.de
Tue Oct 14 16:34:30 EDT 2003


On 14 Oct 2003, Gerhard Venter <- gventer at fish.co.uk wrote:

>  >>> import os
>  >>> K=os.system('curl -gs http://babelfish.altavista.com |grep -ic
>  >>> translate')
> 11
>  >>> print K
> 0

[...]
> My question is why does K not assume the value of 11 and what can I do
> to make it do so.

>>> help(os.system)
Help on built-in function system:

system(...)
    system(command) -> exit_status
    
    Execute the command (a string) in a subshell.

>>> 

So the return value of os.system is the exit status of grep.  If you
want the 11 as return value you need one of the os.popen* functions.

>>> g = os.popen('grep -c e .gnus.el')
>>> g
<open file 'grep -c e .gnus.el', mode 'r' at 0x9ad860>
>>> g.next()
'279\n'
>>> 



   Karl
-- 
Please do *not* send copies of replies to me.
I read the list




More information about the Tutor mailing list