[英]What is the purpose of [] operator while opening a file in python
I see the following syntax in one of the python files. 我在其中一个python文件中看到以下语法。 I can understand that it is reading the file. 我可以理解它正在读取文件。 But I am not sure what the [0][0] are used for 但是我不确定[0] [0]用于什么
lines = open (config[0][0], 'r').readlines()
My config file looks like 我的配置文件看起来像
py0:max0
py1:max1
py2
py3
Could someone please share your comments 有人可以分享您的评论吗
A small modification makes the code better understandable: 进行少量修改即可使代码更易于理解:
filename = config[0][0]
lines = open(filename, 'r').readlines()
You obtain the file name from a variable that contains a list of lists, and then this file is opened and all lines read. 您从包含列表列表的变量中获取文件名,然后打开该文件并读取所有行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.