Run Process Hidden Python

后端 未结 2 1736
醉酒成梦
醉酒成梦 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

    #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)
    

提交回复
热议问题