python little ping script

Hi everyone,

I'm a newby in the python languages, and I try to make some parallels to shell.
My question is how ca I give the information to python that the line 3 "r=...." the string "line" is a variable.

import os, re
line = "localhost"
r = "".join(os.popen("ping line -c 1").readlines())
print r
if re.search("64 bytes from", r):
 print "Site is reachable"
else:
 print "Site is not reachable"

because in this case the ping toll try to reach the hostname line and the host is unknown.

that should be:

import os, re
line = "localhost"
r = "".join(os.popen("ping $line -c 1").readlines())
print r
if re.search("64 bytes from", r):
 print "Site is reachable"
else:
 print "Site is not reachable"

is ther any way to solve this issue in python ?

---------- Post updated at 01:18 AM ---------- Previous update was at 12:16 AM ----------

I found a solution

line = "localhost"
cmd = "ping -c1 " + line
r = "".join(os.popen(cmd).readlines())
r = "".join(os.popen("ping -c1 " + line).readlines())

thanks for your post, it seems to be a good solution. too !!

reg
research3