文件类型:user_pass
- 文件预览
- 文件读取
```python
name_list = open(‘user_pass’, ‘r+’, encoding=’utf-8’) # 打开本地user_pass用户名密码文本,格式为 用户名:密码
name_text = dict(line.strip().split(“:”) for line in name_list if
line) # 将读取到的用户名密码做成字典,.strip()去掉每行未/n回车符,.split(":")将用户名密码通过:分隔开,{'test': 'test'}通过name_text.get{username}可直接获取用户名的密码
print(name_text)
输出结果
{‘用户名1’: ‘密码1’, ‘用户名2’: ‘密码2’}
<a name="PRWFV"></a>
# 文件类型:user_pass.json
1. 文件预览
![image.png](https://cdn.nlark.com/yuque/0/2022/png/2981571/1644462288610-44142803-7815-48b6-9f61-daaeb8f54e1d.png#clientId=ud93c0cb1-ca4d-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=271&id=uc6b62129&margin=%5Bobject%20Object%5D&name=image.png&originHeight=271&originWidth=429&originalType=binary&ratio=1&rotation=0&showTitle=false&size=18037&status=done&style=none&taskId=ub4a09104-f7c1-429d-ae96-1a6697a871f&title=&width=429)
2. 文件读取
```python
import json
with open("user_pass.json", 'r', encoding='UTF-8') as f:
load_dict = json.load(f)
print(load_dict)
# 输出结果
# {'admin': {'name': 'admin', 'psw': 'passadmin'}, 'guest': {'name': 'apple', 'psw': '5'}}