Skip to content

fix UnicodeEncodeError #54

@3mora2

Description

@3mora2

error ->

Traceback (most recent call last):
  File "E:\Projects\Python\QssStylesheetEditor\src\ui\mainwin.py", line 540, in save
    self.saveAs()
  File "E:\Projects\Python\QssStylesheetEditor\src\ui\mainwin.py", line 553, in saveAs
    self.editor.save(self.file.encode("utf-8"))
  File "E:\Projects\Python\QssStylesheetEditor\venvtest\Lib\site-packages\CodeEditor\editor.py", line 366, in save
    outfile.write(self.text())
  File "C:\Users\ammar\AppData\Local\Programs\Python\Python311\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode characters in position 513-517: character maps to <undefined>

please, update lib CodeEditor in editor.py -> Editor class -> save method:

    def save(self, filename):
        """Save the editor contents to the given filename."""
        with open(filename, 'w', newline='', encoding="utf-8") as outfile:
            # 不指定newline,则换行符为各系统默认的换行符(\n, \r, or \r\n, )
            # newline=''表示不转换
            outfile.write(self.text())
            self.setModified(False)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions