Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Use random file

I have this piece of code:

com = "node file1.js {var1} {var2} {var3} {var4} {var5}".format(
    var1 = self.CURRENTENTRY[0],
    var2 = self.CURRENTENTRY[1],
    var3 = self.CURRENTENTRY[2],
    var4 = self.CURRENTENTRY[3],
    var5 = ",".join(elist)
)

I would like to use more .js files (file2.js, file3.js, …, filex.js) and let the script to chose one at random each time.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use following code.

import random

files = ['file1.js', 'file2.js', 'file3.js']

filename = random.choice(files)
com = "node {filename} {var1} {var2} {var3} {var4} {var5}".format(
        filename,
        va1 = self.CURRENTENTRY[0],
        var2 = self.CURRENTENTRY[1],
        var3 = self.CURRENTENTRY[2],
        var4 = self.CURRENTENTRY[3],
        var5 = ",".join(elist)
    )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading