Q:

Python output another python script live

i wan to obtain live output effects of print function in python when i call another python script. For example script1.py print like 10000 numbers. Script script2.py will execute script1.py and will show every print as it come. I search on google and i use something like this:
path_to_file = os.path.dirname(os.path.abspath(__file__)) + "/files/" + script_name
command = "python " + path_to_file
process_handle = Popen(command, shell=True, stdout=PIPE)

while process_handle.poll() is None:
    output = process_handle.stdout.read()
    print("Last output read = " + output)

But the result i get for example 100 numbers is 
Last output read = Number : 1
Number : 2
Number : 3
Number : 4
Number : 5
Number : 6
Number : 7
Number : 8
Number : 9
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 
Last output read = 

A:

path_to_file = os.path.dirname(os.path.abspath(__file__)) + "/files/" + script_name
command = "python " + path_to_file
process_handle = Popen(command, shell=True, stdout=PIPE)

while process_handle.poll() is None:
    for line in iter(process_handle.stdout.readline, ""):
        output = line.decode('utf-8')
        if output != '':
            print('Last number is: ' + output)

Before your code would read the whole output of the program first and then pipe it, thus it would be piping '0/n1/n2/n' etc and not '0\n', '1\n', '2\n' individually. 
Solution is to continously read the data output as such.

