newbie variables question

Chris Gonnerman chris.gonnerman at
Sat Mar 31 08:50:15 CEST 2001

----- Original Message -----
From: "Michael Hall" <py.list at>
Subject: newbie variables question>

> I've been trying to do this:
> SYSPRODIR = /home/admin/systemprofile
> os.system('mv /tmp/install.log SYSPRODIR/install.log')
> No matter how I play around with single and double quotes, this won't
> work.

You're thinking /bin/sh.  Quoting has little to do with it.

> But this does work:
> os.system('mv /tmp/install.log %s/install.log' %s SYSPRODIR)

I hope it actually says:

    os.system('mv /tmp/install.log %s/install.log' % SYSPRODIR)

This is one correct way to do what you want.

> Is this the normal/best way to do this in Python ... seems a little
> convoluted me, like there must be a simpler way. Bash for example would be
> happy with something like:
> mv /tmp/install.log $SYSPRODIR/install.log
> while PHP is happy with things like:
> include ("$SYSPRODIR/install.log");

The other way in Python is this:

    os.system('mv /tmp/install.log ' + SYSPRODIR + '/install.log')

which works fine so long as SYSPRODIR is a string.

Substitution into a string is almost always done with the % operator, as

    "format string" % value

or for multiple values:

    "format string" % (v1, v2, v3)

where the second operand is obviously a tuple.

> Thanks for any advice. I haven't found any clear info about this in
> Learning Python yet.
> Mick

Happy to help.

More information about the Python-list mailing list