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

Converter give error: cannot use a string pattern on a bytes-like object #3

Open
simongcc opened this issue Sep 9, 2023 · 2 comments

Comments

@simongcc
Copy link

simongcc commented Sep 9, 2023

There is an error like this

  File "/somewhere/miniforge3/lib/python3.10/site-packages/opencc/opencc.py", line 67, in convert
    split_string_list = self.split_chars_re.split(string)
TypeError: cannot use a string pattern on a bytes-like object

So the solution is adding a checking to the string returned by the converter like this

def s2t(text):
    if isinstance(text, bytes):
        text = text.decode('utf-8')  # decode bytes to string using utf-8 encoding
    return converter.convert(text)

Then the error will be resolved.
Tested with Simplified Chinese to Traditional Chinese

@t510599
Copy link
Member

t510599 commented Sep 21, 2023

@simongcc
Hi, can I have an example file which make this error occur?
thanks

@jingcodeguy
Copy link

@t510599 Hi Tony, sorry for late reply for I was travelling for a few months.
I have forgotten which book I have used for testing about it. If I happen to see again will let you know.

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

3 participants