Here is small snippet to make you understand:
In python you can import module by passing module name as string. __import__
two script in my snippet:
2.1 main script name is menu.py.
2.2 module name is arsenal which will load based on your input string:
You can extend the main script and module, the way you like. this is just for understanding.
main.py
#!/usr/bin/python
def load_module(name):
return __import__(name)
def what_score(module_name, sc):
return getattr(module_name, 'score')(sc)
if __name__ == '__main__':
print "Input team name: ",
team_name = raw_input().strip()
module_name = load_module(team_name)
print what_score(module_name, 5)
arsenal.py
def score(n):
return 'Score from [%s] is %d' % (__name__, n)
Output:
:tmp:> python menu.py
Input team name: arsenal
Score from [arsenal] is 5
:tmp:>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…