本文整理汇总了Python中program.Program.execute方法的典型用法代码示例。如果您正苦于以下问题:Python Program.execute方法的具体用法?Python Program.execute怎么用?Python Program.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类program.Program
的用法示例。
在下文中一共展示了Program.execute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Commander
# 需要导入模块: from program import Program [as 别名]
# 或者: from program.Program import execute [as 别名]
class Commander(object):
def __init__(self, program):
self.program = Program(program)
self.army = list()
self.enemies = list()
self.army_name = self.find_army_name()
def find_army_name(self):
try:
name = self.do_find_army_name()
except Exception:
# If program fails to implement -n properly, just choose
# a random name.
name = 'army-%d'% random.randint(1,10000000)
return name
def do_find_army_name(self):
arguments = ProgramArguments()
reader = FileReader(self)
output_filename = FileUtils.get_new_filename()
arguments.add('-n')
arguments.add('-o', output_filename)
self.program.execute(arguments)
name = reader.read_name(output_filename)
FileUtils.remove_file(output_filename)
return name
def get_army_name(self):
return self.army_name
def get_army(self):
return self.army
def set_army(self, soldiers):
map(self.set_army_on_soldier, soldiers)
self.army = soldiers
def set_army_on_soldier(self, soldier):
army_name = self.get_army_name()
soldier.set_army_name(army_name)
def add_enemies(self, enemies):
self.enemies.extend(enemies)
def read_file_or_raise(self, filename, writer, context):
reader = FileReader(context)
try:
data = reader.read(filename)
except IOError:
raise MissingFileException(self.army_name, self.program,
writer.get_filename())
except ParsingException, e:
e.set_army_name(self.army_name)
raise e
else:
示例2: main
# 需要导入模块: from program import Program [as 别名]
# 或者: from program.Program import execute [as 别名]
def main():
programa = Program()
return programa.execute()