# Buggy code
def run_config(repl, config_file="~/.ptpython/config.py"):
    """
    Execute REPL config file.

    :param repl: `PythonInput` instance.
    :param config_file: Path of the configuration file.
    """
    assert isinstance(repl, PythonInput)
    assert isinstance(config_file, six.text_type)

    # Expand tildes.
    config_file = os.path.expanduser(config_file)

    def enter_to_continue():
        six.moves.input("\nPress ENTER to continue...")

    # Check whether this file exists.
    if not os.path.exists(config_file):
        print("Impossible to read %r" % config_file)
        enter_to_continue()
        return

    # Run the config file in an empty namespace.
    try:
        namespace = {}

        with open(config_file, "r") as f:
            code = compile(f.read(), config_file, "exec")
            six.exec_(code, namespace, namespace)

        # Now we should have a 'configure' method in this namespace. We call this
        # method with the repl as an argument.
        if "configure" in namespace:
            namespace["configure"](repl)

    except Exception:
        traceback.print_exc()
        enter_to_continue()


# Traceback (UnicodeDecodeError)
Traceback (most recent call last):
File "c:\python36\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python36\Scripts\ptpython.exe\__main__.py", line 9, in <module>
File "c:\python36\lib\site-packages\ptpython\entry_points\run_ptpython.py", line 74, in run
title='Python REPL (ptpython)')
File "c:\python36\lib\site-packages\ptpython\repl.py", line 320, in embed
cli.run()
File "c:\python36\lib\site-packages\prompt_toolkit\interface.py", line 404, in run
self.on_start.fire()
File "c:\python36\lib\site-packages\prompt_toolkit\utils.py", line 60, in fire
self()
File "c:\python36\lib\site-packages\prompt_toolkit\utils.py", line 56, in __call__
handler(self.sender)
File "c:\python36\lib\site-packages\ptpython\repl.py", line 62, in _on_start
code = compile(f.read(), path, 'exec')
File "c:\python36\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 2: character maps to <undefined>

# Fixed code
def run_config(repl, config_file="~/.ptpython/config.py"):
    """
    Execute REPL config file.

    :param repl: `PythonInput` instance.
    :param config_file: Path of the configuration file.
    """
    assert isinstance(repl, PythonInput)
    assert isinstance(config_file, six.text_type)

    # Expand tildes.
    config_file = os.path.expanduser(config_file)

    def enter_to_continue():
        six.moves.input("\nPress ENTER to continue...")

    # Check whether this file exists.
    if not os.path.exists(config_file):
        print("Impossible to read %r" % config_file)
        enter_to_continue()
        return

    # Run the config file in an empty namespace.
    try:
        namespace = {}

        with open(config_file, "rb") as f:
            code = compile(f.read(), config_file, "exec")
            six.exec_(code, namespace, namespace)

        # Now we should have a 'configure' method in this namespace. We call this
        # method with the repl as an argument.
        if "configure" in namespace:
            namespace["configure"](repl)

    except Exception:
        traceback.print_exc()
        enter_to_continue()