How do I pass a variable to os.popen?

Ian Kelly ian.g.kelly at gmail.com
Mon Oct 31 16:41:11 EDT 2011


On Mon, Oct 31, 2011 at 2:16 PM, extraspecialbitter
<pauldavidmena at gmail.com> wrote:
>    cmd = 'ethtool %interface'

That is not Python syntax for string interpolation.  Try:
cmd = 'ethtool %s' % interface

On a side note, os.popen is deprecated.  You should look into using
the higher-level subprocess.check_output instead.

Cheers,
Ian



More information about the Python-list mailing list