简体   繁体   English

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

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

The title sort of explains itself.标题有点自我解释。

Here's my code:这是我的代码:

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))

I don't think it's in any of the modules...我不认为它在任何模块中......

Thanks!谢谢!

Likely name = sys.argv[1] is where you're running into the IndexError.可能name = sys.argv[1]是您遇到 IndexError 的地方。

You're calling the first command line argument without passing anything in. It doesn't prompt you for any input and will fail with an IndexError.您在调用第一个命令行参数时没有传递任何内容。它不会提示您进行任何输入,并且会因 IndexError 而失败。

Edit: Didn't see Grismar's comment!编辑:没有看到 Grismar 的评论!

暂无
暂无

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

相关问题 Python:不知道为什么会出现“ IndexError:列表分配索引超出范围”错误 - Python: not sure why I am getting “IndexError: list assignment index out of range” error 为什么我收到 IndexError: list index out of range 这个函数? - Why am I getting IndexError: list index out of range for this function? 为什么我收到 IndexError: list index out of range - Why am I getting IndexError: list index out of range 为什么在此代码中出现IndexError:list index超出范围? - Why am I getting IndexError: list index out of range in this code? 为什么收到此错误“ IndexError:字符串索引超出范围” - Why am I getting this Error “IndexError: string index out of range” 为什么我得到 IndexError: list index out of range 错误,即使我有一个正确的列表 - Why am I getting IndexError: list index out of range error even though I have a proper list 为什么我会收到此错误? IndexError:列表索引超出范围 - Why am I receiving this error? IndexError: list index out of range 为什么我收到此错误? twitter_list_dict.append(line [0])IndexError:列表索引超出范围 - why am I getting this error? twitter_list_dict.append(line[0]) IndexError: list index out of range 初学者:为什么我会收到此错误:IndexError: list assignment index out of range - Beginner: Why am I getting this error: IndexError: list assignment index out of range IndexError:列表索引超出范围,python3 - IndexError: list index out of range, python3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM