Skip to content

Commit

Permalink
added explicit encoding when reading text files
Browse files Browse the repository at this point in the history
  • Loading branch information
fzumstein committed Dec 11, 2023
1 parent 9d68649 commit 90052e6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions xlwings/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def copy_code(fpath):
'Please install either "pandas" or "pyperclip" to use the copy command.'
)

with open(fpath, "r") as f:
with open(fpath, "r", encoding="utf-8") as f:
if "bas" in str(fpath):
text = (
f.read()
Expand Down Expand Up @@ -791,9 +791,9 @@ def export_vba_modules(book, overwrite=False):
if vb_component.Type == 100:
# Remove the meta info so it can be distinguished from regular
# classes when running "xlwings vba import"
with open(file_path, "r") as f:
with open(file_path, "r", encoding="utf-8") as f:
exported_code = f.readlines()
with open(file_path, "w") as f:
with open(file_path, "w", encoding="utf-8") as f:
f.writelines(exported_code[9:])
return path_to_type

Expand Down Expand Up @@ -845,7 +845,7 @@ def vba_import(args):
pass
book.api.VBProject.VBComponents.Import(path)
elif path.suffix in (".cls", ".frm"):
with open(path, "r") as f:
with open(path, "r", encoding="utf-8") as f:
vba_code = f.readlines()
if vba_code:
if vba_code[0].startswith("VERSION "):
Expand Down Expand Up @@ -902,7 +902,7 @@ def vba_edit(args):
module_type = path_to_type[path]
vb_component = book.api.VBProject.VBComponents(module_name)
if change_type == Change.modified:
with open(path, "r") as f:
with open(path, "r", encoding="utf-8") as f:
vba_code = f.readlines()
line_count = vb_component.CodeModule.CountOfLines
if line_count > 0:
Expand Down

0 comments on commit 90052e6

Please sign in to comment.