【发布时间】:2022-07-23 06:08:54
【问题描述】:
我试图弄清楚如何找到列表中某个部分的长度。例如,我的程序在我的配置文件中有一个用户名和密码。有没有办法弄清楚有多少个用户名?如果是,那怎么办?
#Also any of the spaces you see between the words are just for reading's sake
#and won't be there in the final program
firsttime:
True
Username:
user1
user2
Password:
pass1
pass2
Key:
key
Theme:
#303030
white
【问题讨论】:
-
如果您可以控制配置文件的格式,那么您应该考虑使用像 json 或 yaml 这样的数据格式,这使得这种类型的结构化数据交互更加容易。
-
就像@Conor 说的:使用
json配置文件并使用json标准模块读取它 -
感谢您的建议。我真的不知道如何使用,但我看看。