How to run 2 python scripts at the same time side by side on the same line?

Could I run 2 python scripts at the same time side by side output on the same line in this same format but with scripts?

from itertools import izip_longest

with open("file1") as textfile1, open("file2") as textfile2:
for x, y in izip_longest(textfile1, textfile2, fillvalue=""):
    x = x.strip()
    y = y.strip()
    print("{0}{1}".format(x, y))

without contents of file1 file2 and required output I'm guessing to a certain extent, but try:

paste -d'\0' file1 file2
$ cat file1
Record A
Recrod B
Record D

$ cat file2
1
2
3
4

$ paste -d'\0' file1 file2
Record A1
Recrod B2
Record D3
4

Using pr

$ cat f1 
Record A
Recrod B
Record D

$ cat f2
1
2
3
4

$ pr -mtJS f1 f2
Record A1
Recrod B2
Record D3
4
1 Like

I think OP is asking for side by side printing of the output of two python scripts as they run, and has shown as an example, concatenation of two text files using izip_longest().

@bigvito19: Instead , do you have the option to write them as one script and format the output as you need it?

2 Likes

Yes, or call the two scripts in another script, store the results of each script (as as function for example) and write them on a single line as output.

This is very easy to do (and is the way most sys admins would do this, I think). Just convert the script to a function, call it twice in another script, and format the output. Easy as pie. Simplicity is always best, based on my experiences.