Send value of variable that is in a loop from one script to another script

前端 未结 2 1272
遥遥无期
遥遥无期 2021-01-27 08:22

I\'ve been fiddling with sending a variable from one script to another and have done some basic things pretty easily, but I have gotten stuck and was hoping to get some input.

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-27 09:11

    main.py

    from subprocess import Popen, PIPE
    import sys
    
    p = Popen(['py', 'client.py'], stdout=PIPE)
    while True:
        o = p.stdout.read(1)
        if o:
            sys.stdout.write(o.decode('utf-8'))
            sys.stdout.flush()
            print '*'
        else: break
    

    client.py

    import time
    for a in xrange(3):
        time.sleep(a)
        print a
    

    OUT:

    0*
    *
    
    *
    1*
    *
    
    *
    2*
    *
    
    *
    

提交回复
热议问题