我有一个程序需要使用类似的东西:
file1=open("cliente\\config.ini","r")
print file1.read().split(",")
user=file1.read().split(",")[0]
passwd=file1.read().split(",")[1]
domain=file1.read().split(",")[2]
file1.close()
在该文件中有 3 个字符串,由“,”(用户、密码、域)分隔。
这是输出:
['user', 'pass', 'domain']
Traceback (most recent call last):
File "C:\Users\default.default-PC\proyectoseclipse\dnsrat\prueba.py", line 8, in <module>
passwd=file1.read().split(",")[1]
IndexError: list index out of range
我正在使用列表中的 0、1 和 2 字符串,所以我没有使用不存在的字符串。
那么,为什么我有一个错误?
非常感谢你。