English 中文(简体)
粉碎:替代分处理
原标题:Python: substitution in subprocess call

页: 1 我试图这样做:

myStr = " (insert "%g") " %i
    subprocess.Popen(["emacs", "--batch", "+83:28", "md.mdp", "--eval", 
                      eval("myStr"), "-f", "save-buffer", "--kill"], 
                     stdout=subprocess.PIPE).wait()

并如上:

subprocess.Popen(["emacs", "--batch", "+83:28", "md.mdp", "--eval", 
                  " (insert "%g") " %i, "-f", "save-buffer", "--kill"], 
                 stdout=subprocess.PIPE).wait()

并如上:

subprocess.Popen(["emacs", "--batch", "+83:28", "md.mdp", "--eval", 
                  (" (insert "%g") " %i), "-f", "save-buffer", "--kill"], 
                 stdout=subprocess.PIPE).wait()

但是,这些工作都没有。 Can 你们帮助我让它right?

而且——情况是这样——当<代码>系统(“bashtor”)时,是否有t <代码>wait?

http://www.ohchr.org。

它是为某一参数的不同价值进行计算机模拟的。 它复制每个跑道的基多塔迪尔,然后修改参数档案(标明价值),然后进行模拟和回击。

This doesn t produce error - but also doesn t insert the value of i in the md.mdp:

myStr = " (insert "%g") " %i
subprocess.Popen(["emacs", "--batch", "+83:28", "md.mdp", "--eval", 
                  myStr, "-f", "save-buffer", "--kill"], 
                 stdout=subprocess.PIPE).wait()

也没有帮助:

myStr = " (insert \"%g\") " %i

以下变量也不加一字:

subprocess.Popen(["emacs", "--batch", "+83:28", "md.mdp", "--eval", 
              " (insert "%g") " %i, "-f", "save-buffer", "--kill"], 
             stdout=subprocess.PIPE).wait()

subprocess.Popen(["emacs", "--batch", "+83:28", "md.mdp", "--eval", 
              (" (insert "%g") " %i), "-f", "save-buffer", "--kill"], 
             stdout=subprocess.PIPE).wait()
最佳回答

以下著作:

subprocess.Popen(["emacs", "--batch", "+83:28", "md.mdp", "--eval", 
                 eval(" (insert "%g") " %i), "-f", "save-buffer", "--kill"], 
                 stdout=subprocess.PIPE).wait()

http://www.un.org/Depts/DGACM/index_spanish.htm

有时 你们不需要打折:

subprocess.Popen(["grompp", "-f", "%s" %opts.myMdp, "-c", "%s" %opts.myGro,
                 "-p", "%s" %opts.myTop], stdout=subprocess.PIPE).wait()

When I do (insert "%g") %i it gives

Traceback (most recent call last): File
"/home/boris/its/plts/bio/bk-simulates-work.py", line 100, in <module>

subprocess.Popen(["emacs", "--batch", "+83:28", "md.mdp", "--eval",
 (insert "%g")  %i, "-f", "save-buffer", "--kill"],
stdout=subprocess.PIPE).wait() 

NameError: name  i  is not defined

虽然它实际上作了界定,因为指挥范围在<代码>内......。

当我做<代码>时(插入<%g”:

subprocess.Popen(["emacs", "--batch", "+83:28", "md.mdp", "--eval",
 (insert "%g") , "-f", "save-buffer", "--kill"],
stdout=subprocess.PIPE).wait()

仅加百分比。

实际上,我没有这样做(在档案中填入某个地方的一 i),也没有再做些什么:

myInput = open(opts.myMdp,  r )
myTempFile = opts.myMdp +  ~~~ 
myOutput = open(myTempFile,  w )
for line in myInput:
    myOutput.write(line.replace(opts.myToken, "%g" %myValue))
myOutput.close()
myInput.close()
os.rename(myTempFile, opts.myMdp)
问题回答

I d say that the problem is that you don t need to quote the insert statement part. The reason for this is that you use quotes in a shell to make it clear that the string between quotes is to be passed as a single argument.

但是,在<代码>分处理中,P open 您重新使用一个阵列来履行同样的功能,因此不必引用。 换言之,在一纸空文中,斜体投向正在启动的进程,在<代码>的分处理中。 开放式<>代码>电话正在通过。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签