def write_text_file(filename, contents, encoding='utf-8'):
    '\n    Writes a file under python3 with encoding (default UTF-8).\n    Also works under python2, without encoding.\n    Uses the EAFP (https://docs.python.org/2/glossary.html#term-eafp)\n    principle.\n    '
    try:
        with open(filename, 'w', encoding) as f:
            f.write(contents)
    except TypeError:
        with open(filename, 'w') as f:
            f.write(contents)
Writes a file under python3 with encoding (default UTF-8).
Also works under python2, without encoding.
Uses the EAFP (https://docs.python.org/2/glossary.html#term-eafp)
principle.
def write_text_file(filename, contents, encoding='utf-8'):
    '\n    Writes a file under python3 with encoding (default UTF-8).\n    Also works under python2, without encoding.\n    Uses the EAFP (https://docs.python.org/2/glossary.html#term-eafp)\n    principle.\n    '
    try:
        with open(filename, 'w', encoding) as f:
            f.write(contents)
    except TypeError:
        with open(filename, 'w') as f:
            f.write(contents)