代码之家  ›  专栏  ›  技术社区  ›  Abhishek Bajaj

p4python运行描述未返回列表

  •  -1
  • Abhishek Bajaj  · 技术社区  · 8 年前
    p4.connect()                   # Connect to the Perforce Server
    info = p4.run("info")          # Run "p4 info" (returns a dict)
    changes_results = p4.run('changes','-s','submitted', '//components/rel/...@2017/11/01,@2017/12/31')
    
    
    changes_lists = []
    
    
    for change_result in changes_results:
        change_list = change_result['change']
        changes_lists.append(change_list)
    
    
    
    print('Total Change list found ', len(changes_lists))
    for idx_main, change_id in enumerate(changes_lists):
        print('\n\n\n', change_id, idx_main)
        result = p4.run('describe', change_id)
        print(result)
        depotfiles = result[0]["depotFile"]
        filesrevision = result[0]["rev"]
    

    对于一些更改列表,这是非常好的p4。run正在返回列表,我可以提取更改列表文件及其修订号。

    但有时p4。run没有返回正确的列表,而是返回字符串,我无法提取变更列表文件及其修订号,并给出以下错误

    depotFile=结果[0][“depotFile”] TypeError:字符串索引必须是整数

    P4或我的代码是否有问题。

    1 回复  |  直到 8 年前
        1
  •  2
  •   Samwise    8 年前

    获取变更列表(或任何其他地方)中文件列表的最简单方法是 p4 files 命令

    一、 e.更换:

    result = p4.run('describe', change_id)
    print(result)
    depotfiles = result[0]["depotFile"]
    filesrevision = result[0]["rev"]
    

    使用:

    for result in p4.run('files', '@='+change_id):
        print(result)
        depotfiles = result["depotFile"]
        filesrevision = result["rev"]
    
    推荐文章