python - JSON 文件每行打印一个字符
问题描述
我正在尝试打印主要的总称,但每次我这样做时,它每行返回一个字符,我如何制作它以便将整个总称打印在一行中。
结果:
@
g
m
a
i
l
.
c
o
m
预期结果:@gmail.com
JSON 代码:
{
"primaryCatchall": "@gmail.com",
"secondaryCatchall": "@gmail.com",
"password": "password123",
"repeat": 5
}
Python代码:
import json
with open('tempemail.txt', 'r') as myfile1:
email1 = myfile1.read()
with open('config.json', 'r') as config:
PrimaryCatchall = json.load(config)
for primaryCatchall in PrimaryCatchall['primaryCatchall']:
with open('accounts.txt', 'a') as accounts:
print(primaryCatchall)
#accounts.write("\n")
#accounts.write(email1)
#accounts.write(primaryCatchall)
解决方案
在您的代码中,您将 JSON 作为变量 PrimaryCatchall 加载。紧接着,你为 PrimaryCatchall 运行了一个for 循环,它得到了每个单独的字符。摆脱那个for循环来解决问题
推荐阅读
- python - 使用opencv定义要提取的颜色
- wordpress - Wordpress 联系表格 - 将表格发送到群组电子邮件
- javascript - 在 Jest 中模拟单个依赖函数
- c++ - 如何在 if 语句条件 C++ 中使用字符串变量?
- android - 在 onOptionsItemSelected 中获取特定的 MenuItem 并将其设置为 SHOW_AS_ACTION_NEVER
- hashicorp-vault - 如何在保管库中生成签名 ID 令牌?
- angular - 允许访问 assets/files 子文件夹中的 pdf 文件,并使用 htaccess angular redirect all to index.html
- python-3.x - 导入我的包时出现 ModuleNotFoundError,但单独运行时不会
- python - Python - 通过 c_rating 创建平均估计工资条形图,但按性别执行 facet_wrap
- r - R中的二次规划求解函数