Home > Back-end >  how can i use the data i have in my json file to make the script work?
how can i use the data i have in my json file to make the script work?

Time:01-05

I'm recently learning python and I came across this exercise where I have to create a mail generator with the catchall, the latter must be inserted in an external json file, the only problem is that I can't tell the program to use the catchall which is placed in the json file, can anyone help me? Thanks in advance

this is part of code: need to fix email_format

for i in range (emails_number):
                letters_list = [string.digits, string.ascii_lowercase, string.ascii_uppercase]

                letters_list_to_str = "".join(letters_list)

                email_format = (json.data file)

                email_generated = "".join(random.choices(letters_list_to_str, k=chars))   email_format

                print(email_generated)
email_gen()

CodePudding user response:

If you want to open a json file in general, use:

import json
with open(jsonfilepath, "r") as f:
    data = json.load(f)

then you can access the information in the file like a dictionary:

email_format=data["catchall"]
  • Related