python3 exec to use dynamically loaded modules

xxglsvr.py

import sys

# Locals () function to obtain a local variable dictionary.
After the # value after the acquisition variable you can modify the dictionary from the local
DEF main (procName):
  LOC = about locals ()
  Exec ( "% S Import from call_sub" procName%)
  call_sub LOC = [ 'call_sub']
  call_sub ( " private "+ procName)

the __name__ == IF '__main__':
  # locals not defined in a global variable ()
  procName = "xxglsvr01"
  Exec ( "% S Import from call_sub" procName%)
  call_sub ( "public" + procName)

  main("xxglsvr01")
  main("xxglsvr02")

---------------------------------------------------------------------------

xxglsvr01.py

import sys

def call_sub(params):
  print("call xxglsvr01(%s)" % params)

---------------------------------------------------------------------------

xxglsvr02.py

import sys

def call_sub(params):
  print("call xxglsvr02(%s)" % params)

Guess you like

Origin www.cnblogs.com/zsfishman/p/11404305.html