pthom / hello_imgui

Hello, Dear ImGui: unleash your creativity in app development and prototyping
https://pthom.github.io/hello_imgui
MIT License
606 stars 91 forks source link

Should add `encoding='utf8'` to open #49

Closed district10 closed 1 year ago

district10 commented 1 year ago

Given OS=Windows, imgui-bundle=0.8.5

Click and crash here:

image

Log:

Traceback (most recent call last):
  File "C:\Users\tangz\test.py", line 183, in <module>
    immapp.run(demo_gui, with_markdown=True, window_size=(1000, 800))  # type: ignore
  File "C:\Users\tangz\test.py", line 172, in demo_gui
    show_markdown_file("ibd_faq")
  File "C:\Users\tangz\miniconda3\lib\site-packages\imgui_bundle\demos_python\demo_utils\api_demos.py", line 79, in show_markdown_file
    code = read_markdown_code(doc_filename)
  File "C:\Users\tangz\miniconda3\lib\site-packages\imgui_bundle\demos_python\demo_utils\api_demos.py", line 106, in read_markdown_code
    r = read_code(doc_file)
  File "C:\Users\tangz\miniconda3\lib\site-packages\imgui_bundle\demos_python\demo_utils\functional_utils.py", line 11, in wrapper
    cache[key] = func(*args, **kwargs)
  File "C:\Users\tangz\miniconda3\lib\site-packages\imgui_bundle\demos_python\demo_utils\api_demos.py", line 88, in read_code
    r = f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0x8b in position 7774: illegal multibyte sequence

Need to add encoding='utf8' to open here:

@memoize
def read_code(filename: str) -> str:
    if not os.path.isfile(filename):
        return ""
    with open(filename, encoding='utf8') as f: # a small fix
        r = f.read()
        return r
pthom commented 1 year ago

Thanks! Would you like to add a PR for this?

district10 commented 1 year ago

Thanks! Would you like to add a PR for this?

Sure, I'll give it a try.

district10 commented 1 year ago

I issued to the wrong repo đŸ˜… (I was browsing code & docs, did't realize it.)

Follow up at https://github.com/pthom/imgui_bundle/pull/91

Now I close this issue.