Should add `encoding='utf8'` to open
district10 opened this issue · comments
Given OS=Windows, imgui-bundle=0.8.5
Click and crash here:
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
Thanks! Would you like to add a PR for this?
Thanks! Would you like to add a PR for this?
Sure, I'll give it a try.
I issued to the wrong repo 😅 (I was browsing code & docs, did't realize it.)
Follow up at pthom/imgui_bundle#91
Now I close this issue.