本文整理汇总了Python中job.Job.set_global方法的典型用法代码示例。如果您正苦于以下问题:Python Job.set_global方法的具体用法?Python Job.set_global怎么用?Python Job.set_global使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类job.Job
的用法示例。
在下文中一共展示了Job.set_global方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: everything
# 需要导入模块: from job import Job [as 别名]
# 或者: from job.Job import set_global [as 别名]
now we have everything (from files and command line) in the CFG.
(of course you could produce more configs and put them in to the CFG.)
but this CFG is nothing connected to the job flow.
we often need to concatenate a filepath by the directory in the configs.
for example, some_file_path = CFG['dir1']+'/'+CFG['dir2']+'/'+CFG['file']
this thing will be repeated over and over. scary, right.
we could utilized the power of config mechanism we mentioned in the tutorial_04 -
declare once, use anywhere. but this time we declare the picked config in
Job singleton rather than specific JobNode or JobBlock object.
choose the configs you need in the process and all the job in the process
can easily access those configs.
'''
Job.set_global('a very long path blah blah', CFG['a very long path blah blah'])
Job.set_global('another very long path blah blah', CFG['another very long path blah blah'])
Job.set_global('yet another very long path blah blah', CFG['yet another very long path blah blah'])
'''
wait, do you notice that we are repeatedly typing the variable name?
we don't like bad smell, even it is slightly.
we introduce a helper in the config module, called pickup_from_dict
applying it with the python build-in method, map, could ease your work
'''
configs_for_jobs = config.pickup_from_dict(CFG, [
'a very long path blah blah', # you can even
'another very long path blah blah', # make some tidy
'yet another very long path blah blah', # comment here
])
map(lambda key: Job.set_global(key, CFG[key]), configs_for_jobs.keys())