Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Charmap codec issue #210

Open
sazzadDAI opened this issue Dec 24, 2024 · 0 comments
Open

Charmap codec issue #210

sazzadDAI opened this issue Dec 24, 2024 · 0 comments

Comments

@sazzadDAI
Copy link

I was face this issue,


Traceback (most recent call last):
  File "D:\Devolvedai_work\Devolved_AI_Data_Preparation\perser_experiments\test.py", line 9, in <module>
    megaparse.save(r"D:/Devolvedai_work/Devolved_AI_Data_Preparation/perser_experiments/1.md")
  File "D:\Devolvedai_work\Devolved_AI_Data_Preparation\venv\Lib\site-packages\megaparse\megaparse.py", line 133, in save
    f.write(self.last_parsed_document)
  File "C:\Users\hp\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 character '\u0338' in position 12572: character maps to <undefined>

It solved by creating a save function manually. Here i just added the encoding parameters


def save(file_path:str) -> None:
    os.makedirs(os.path.dirname(file_path), exist_ok=True)
    with open(file_path, "w+", encoding="utf-8") as f:  # Specify UTF-8 encoding
        f.write(megaparse.last_parsed_document)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant