-1

我有以下代码,我试图通过“或”项目和分支列表组合来构造一个表达式......我编写了大部分代码......我需要关于如何创建这个表达式的想法,我有一个样本输入和预期输出以便更好地理解

'''
projects.txt
platform/vendor/pro/code
platform/vendor/source/data
external/gps/data

EXPECTED OUTPUT:-
project:platform/vendor/pro/code branch:ab_mr1 OR project:platform/vendor/source/data branch:b_ar2 OR external/gps/data branch:c_ar3

'''
def getbranch_project (project):
    if project == "platform/vendor/pro/code" :
        branch = 'ab_mr1'

    if project == "platform/vendor/source/data" :
        branch = 'b_ar2'

    if project == "external/gps/data" :
        branch = 'c_ar3'

    return branch

def main ():

    with open('projects.txt','r') as f :
        for line in f :
            project = line.strip()
            branch = getbranch_project(project)
            print "PROJECT:" + project
            print "BRANCH: " + branch
            #project_branch_list

    print project_branch_list

if __name__ == '__main__':
      main()
4

1 回答 1

1
" OR ".join(["%s branch:%s"%(line.strip(),getbranch_project(line.strip())) for line in f])
于 2013-07-22T23:48:38.357 回答