0

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()
Mike Scotty
  • 10,530
  • 5
  • 38
  • 50
Riccardo
  • 3
  • 1
  • 1
    Does this answer your question? [Reading JSON from a file](https://stackoverflow.com/questions/20199126/reading-json-from-a-file) – Mike Scotty Jan 04 '23 at 08:43
  • Welcome to Stack Overflow! You will find help here... provided you ask *good* questions! As a new user, you really should read [ask] to understand the way to ask questions that will get good answers. Specifically we need a minimal version of your current code (fine till here) and **enough input and expected output data** to reproduce your current problem. After reading twice your question I still cannot guess what is your precise problem, so I cannot help your... – Serge Ballesta Jan 04 '23 at 09:07

1 Answers1

0

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"]
Dan
  • 156
  • 5