JSON文件每行打印一个字符

2024-09-28 22:22:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图打印主catchall,但每次打印时,它每行返回一个字符,如何使它在一行中打印整个catchall

结果:

@
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)

Tags: 代码txtcomconfigjsonaswithopen