[英]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.