Run Process Hidden Python

后端 未结 2 1737
醉酒成梦
醉酒成梦 2021-01-29 03:18

I am new in python and I making a new code and I need a little help

Main file :

import os
import time
import sys
import app
import dbg
import dbg
import         


        
相关标签:
2条回答
  • 2021-01-29 03:53

    Why not doing this: define a method in the module you import and call this method 5 times in a loop with a certain time.sleep(x) in each iteration.

    Edit:

    Consider this is your module to import (e.g. very_good_module.py):

    def interesting_action():
        print "Wow, I did not expect this! This is a very good module."
    

    Now your main module:

    import time
    import very_good_module
    
    [...your code...]
    
    if __name__ == "__main__":
        while True:
            very_good_module.interesting_action()
            time.sleep(5)
    
    0 讨论(0)
  • 2021-01-29 03:53
    #my_module.py (print hello once)
    print "hello"
    
    #main (print hello n times)
    import time
    
    import my_module # this will print hello
    import my_module # this will not print hello
    reload(my_module) # this will print hello
    for i in xrange(n-2):
        reload(my_module) #this will print hello n-2 times
        time.sleep(seconds_to_sleep)
    

    Note: my_module must be imported before it can be reloaded.

    .

    I think it's preferable way to include a function in your module which executes, and then call this function. (As for one thing reload is a rather expensive task.) For example:

    #my_module2 (contains function run which prints hello once)
    def run():
        print "hello"
    
    #main2 (prints hello n times)
    import time
    
    import my_module2 #this won't print anything
    for i in xrange(n):
        my_module2.run() #this will print "hello" n times
        time.sleep(seconds_to_sleep)
    
    0 讨论(0)
提交回复
热议问题