[Tutor] (no subject)

Glen Bunting Glen@ihello-inc.com
Thu, 8 Mar 2001 14:15:42 -0800


Thanks Danny,

I have another question in the same area.  

Here is the code that I have so far:
>>>SERVER = popen('cut --character=5- eachName')
>>>LOOK_FOR = popen('cut --character=9- eachName')
RESULTS = os.system(curl --include --max-time 30 SERVER | grep LOOK_FOR')

I just need to verify that what is specified in LOOK_FOR is there or not.
What is wrong with the last line?

Glen Bunting 




-----Original Message-----
From: Daniel Yoo [mailto:dyoo@hkn.eecs.berkeley.edu]
Sent: Thursday, March 08, 2001 12:48 PM
To: Glen Bunting
Cc: tutor@python.org
Subject: Re: [Tutor] (no subject)


On Thu, 8 Mar 2001, Glen Bunting wrote:

> I have what I hope is a very easy question.  I need to save the
> results of a command to a variable but I am not sure how to go about
> doing it.  This is what I have done so far:
> 
> >>>import os
> >>>test  = os.system('cut --character=5- ActsAutomation,ihello,com')

The os.system() function returns the "errorlevel" of its command, which is
often different from its printed output.  (This errorlevel value is useful
when you're writing shell scripts that check for the success or failure of
a command.) That's where the zero is coming from.

What you'll want to use instead is os.popen(), which gives us a
"file"-like object.  From this, we can read off the program's output.

For example:

###
>>> import os
>>> output = os.popen('ls *.txt').read()
>>> print output
indrel.txt
list.txt
rules.txt
sentenceword.txt
###

will call the ls command, get the file, read() off all of its string
contents, and store that into our output.

If you have more questions, please feel free to ask us.


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