python, os.system() function. howto use python variables?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
That is just printing out the string literals you are passing to echo - i am looking to resolve the python varaible myCoolVariable before the execution of echo in the sysem() call.
For example, I would like:
Code:
$ python
>>>hamburger="potato"
>>>import os
>>>os.system("echo 'hamburger'")
to somehow produce
Code:
potato
0
in this case i could just write "potato" directly, but things get stickier when i want to say
Code:
hamburger=os.system('echo $MY_SHELL_VAR | sed "s/longsed/replacement/g"')
, or something of that flavour
Last edited by jhwilliams; 07-26-2007 at 02:01 PM.
bash$ python
Python 2.4.3 (#1, May 18 2006, 07:40:45)
[GCC 3.3.3 (cygwin special)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from os import system
>>> food = 'spam'
>>> system('echo %(food)s' % locals())
spam
0
>>>
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.