English 中文(简体)
多次执行假装
原标题:execute python script multiple times

我不敢肯定这样做的最佳方式,但我有一纸空文作为一页。 该书的最后产出是两卷x1.txt和 y1.txt。

基本上,我想用这封信说1 000次,每篇都写上我两个文本的档案,有新名字,即x1.txt + y1.txt,然后是第二版X2.txt和 y2.txt。

想到这一点,最好用像这样的东西来开始整个文字。

runs=xrange(:999)
for i in runs:

##run the script

之后,完成部分内容。

    for i in runs:
        filnameA=prefix += "a"+i


open("filnamea.txt", "w").write( 
 .join( 	 .join(x for x in g if x) for g in grouper(7, values)))


    for i in runs:
        filnameB=prefix += "a"+i


open("filnameB.txt", "w").write( 
 .join( 	 .join(x for x in g if x) for g in grouper(7, values)))

这是否真正是这样做的最佳方式? 我不是这样。

我知道你可以读到<代码>进口时间<>/代码>,并写一个数字,即数学时间,但这一时间将留待日后处理。

最佳回答

如果您的计算机拥有平行运行的资源,你可以使用<代码>多处理<>代码>。 否则,就使用一种循环来依次加以执行。

你的问话很不明确,你们中哪一部分人 st。 你们是否应该利用 lo? 如果是的话,我的回答是上文。 还是需要帮助确定档案名称? 你们可以这样做:

import sys

def myscript(iteration_number):
    xfile_name = "x%d.txt" % iteration_number
    yfile_name = "y%d.txt" % iteration_number
    with open(xfile_name, "w") as xf:
        with open(yfile_name, "w") as yf:
            ... whatever your script does goes here

def main(unused_command_line_args):
    for i in xrange(1000):
        myscript(i)
    return 0

if __name__ ==  __main__ :
    sys.exit(main(sys.argv))
问题回答
import subprocess
import sys

script_name =  dummy_file.py 
output_prefix =  out_ 
n_iter = 5

for i in range(n_iter):
    output_file = output_prefix + str(i) +  .txt 
    sys.stdout = open(output_file,  w )
    subprocess.call([ python , script_name], stdout=sys.stdout, stderr=subprocess.STDOUT)

在进行这项工作时,请查阅5份产出文本文件(0.txt,......,4.txt)。

I m not sure, but maybe, it can help: Suppose, I want to print hello 10 times, without manually writing it 10 times. For doing this, I can define a function :

    #Function for printing hello 10 times:
    def func(x):
       x="hello"
       i=1
       while i<10 :
           print(x)
           i += 1
       else :
           print(x)

    
    print(func(1))




相关问题
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 ]="...

热门标签