繁体   English   中英

为什么我在 Python3 中收到此错误:IndexError:列表索引超出范围

[英]Why am I getting this error in Python3: IndexError: list index out of range

标题有点自我解释。

这是我的代码:

import subprocess
import os
import sys

def log_face(name):
    #create a directory under the training folder with the new persons name
    path = ("./images/train/" + name)
    if not os.path.exists(path):
        mkdirexe = ("mkdir " + path)
        subprocess.call([mkdirexe], shell=True)
    
    #copy the most recent image into the new named folder
    copyexe = ("cp image_cam.jpg " + path)
    subprocess.call([copyexe], shell=True)

#if called direct then run the function
if __name__ == '__main__':
    name = sys.argv[1]
    print(log_face(name))

我不认为它在任何模块中......

谢谢!

可能name = sys.argv[1]是您遇到 IndexError 的地方。

您在调用第一个命令行参数时没有传递任何内容。它不会提示您进行任何输入,并且会因 IndexError 而失败。

编辑:没有看到 Grismar 的评论!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM