社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

无法在python中打印列表值

ebo ahmad • 5 年前 • 1503 次点击  

我正在尝试组织一点服务器日志,这些日志被“”分隔开。 现在我想改变项目的位置,当我把它们放在一个列表中,并试图打印出来保存到一个新的文件,它给了我

print(result[0])
IndexError: list index out of range

列表中的每个位置都是一样的,不仅是0

with open("logs-DD-MM-YYYY.txt") as f:
     for line in f:
         result = line.split('|')
         print(result[0])
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/44076
 
1503 次点击  
文章 [ 2 ]  |  最新文章 5 年前