title: Is there any way to use generator and open a file?
body: <p>I'm currently working on a discord.py bot, looking for using generators more often in my code.
  But I'm having an error when I try to initialize an object method with an output generator.
  Here is what I've tried to do:</p>
  
  <pre><code>def get_language_config(member: Member):
      [role] = [role.name for role in member.roles if role.name in LANGS]
      return LANGS_TO_CONFIG[role]
  
  
  @client.command(name="ip")
  async def ip_command(ctx):
      sender = ctx.author
      translation = get_language_config(sender)
      data = Data(translation).read("langs")["IP_COMMAND"] # Here is the line that seems raise a problem.
      embed = BaseEmbed(title=data["title"], description=data["description"])
      embed.add_field(name=data["field_1"][0], value=data["field_1"][1])
      await ctx.send(embed=embed, file=BaseEmbed.BASIC_FILE)
  </code></pre>
  
  <p>Here is the Data() object class:</p>
  
  <pre><code>import json
  
  
  class Data:
      def __init__(self, data):
          self.data = data
  
      def update(self, key, value):
          with open("data/config.json", "r", encoding="utf-8") as file:
              json_data = json.load(file)
              json_data[self.data][key] = value
          with open("data/config.json", "w") as file:
              json.dump(json_data, file, indent=2)
  
      def read(self, file: str):
          with open("data/%s.json" % file, "r+", encoding="utf-8") as json_file:
              data = json.load(json_file)
          return data[self.data]
  </code></pre>
  
  <p>The output error:</p>
  
  <pre><code>ValueError: I/O operation on closed file
  </code></pre>
  
  <p>P.S.: I'm sorry for my speaking language (I'm french) and it is the first time I post anything on the web-site.</p>