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.
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.