| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
- >>> c=os.walk('C:\\Users\\lyl\\AppData\\Local\\Programs\\Python\\Python39\\ccc')
 
 - >>> c[:]
 
 - Traceback (most recent call last):
 
 -   File "<pyshell#13>", line 1, in <module>
 
 -     c[:]
 
 - TypeError: 'generator' object is not subscriptable
 
 - >>> c[1]
 
 - Traceback (most recent call last):
 
 -   File "<pyshell#14>", line 1, in <module>
 
 -     c[1]
 
 - TypeError: 'generator' object is not subscriptable
 
 - >>> list(c)
 
 - [('C:\\Users\\lyl\\AppData\\Local\\Programs\\Python\\Python39\\ccc', [], ['123.txt', '1234.txt', '234.txt', '39.py', '40.py', '41.py', '42.py', '890.txt', 'LICENSE.txt', 'NEWS.txt', 'python.exe', 'python3.dll', 'python39.dll', 'pythonw.exe'])]
 
 - >>> c(1)
 
 - Traceback (most recent call last):
 
 -   File "<pyshell#16>", line 1, in <module>
 
 -     c(1)
 
 - TypeError: 'generator' object is not callable
 
 - >>> 
 
  复制代码 
 
为什么无法访问元组里面的元素呢,如果要访问应该如何操作?
全桥整流 发表于 2021-9-18 09:52 
>>> c=os.walk('C:\%users\\lyl\\AppData\\Local\\Programs\\Python\\Python39\\ccc') 
>>> list(c)[0][1 ... 
先转列表,增设一个变量xx=list(c)  
 
 
 |   
 
 
 
 |