code: def self_generate(output_filename, filename="iso3166-1.csv"):  # pragma: no cover
      
      import csv
      import re
  
      countries = []
      alt_codes = []
      with open(filename, "r") as csv_file:
          for row in csv.reader(csv_file):
              name = row[0].rstrip("*")
              name = re.sub(r"\(the\)", "", name)
              if name:
                  countries.append((name, row[1]))
                  alt_codes.append((row[1], row[2], int(row[3])))
      with open(__file__, "r") as source_file:
          contents = source_file.read()
      # Write countries.
      bits = re.match("(.*\nCOUNTRIES = \{\n)(.*?)(\n\}.*)", contents, re.DOTALL).groups()
      country_list = []
      for name, code in countries:
          name = name.replace('"', r"\"").strip()
          country_list.append('    "{code}": _("{name}"),'.format(name=name, code=code))
      content = bits[0]
      content += "\n".join(country_list)
      # Write alt codes.
      alt_bits = re.match(
          "(.*\nALT_CODES = \{\n)(.*)(\n\}.*)", bits[2], re.DOTALL
      ).groups()
      alt_list = []
      for code, code3, codenum in alt_codes:
          name = name.replace('"', r"\"").strip()
          alt_list.append(
              '    "{code}": ("{code3}", {codenum}),'.format(
                  code=code, code3=code3, codenum=codenum
              )
          )
      content += alt_bits[0]
      content += "\n".join(alt_list)
      content += alt_bits[2]
      # Generate file.
      with open(output_filename, "w") as output_file:
          output_file.write(content)
      return countries
docs: The following code can be used for self-generation of this file.
  
      It requires a UTF-8 CSV file containing the short ISO name and two letter
      country code as the first two columns.