Is it possible to cross reference bash and python variables in python script

Viewed 284

I can get a value n when I run a shell command using os.system in the python script, but I also need to sum it up to get a total number for subsequent computation in the python script,

total=0
for i in xrange(1,8):
    os.system('n=$(qstat -n1 | grep -o node'+str(i)+' | wc -l)  && echo $n')

Is it possible? Also is it possible to use python variable in shell command, something like

os.system('echo $total')
2 Answers
Related