Jump to content

[PYTHON] Dealing with weird characters. (Unicode.)

Wictorian

IS there a way to prevent weird characters? for instance when I print a letter like "Ş" there is no problem, but when I read a file and turn it into a list and print it, then it print weird characters like this: algılanabilir

I have found some ways to fix this but can't I prevent it from happening? I had this issue using pickle and it was fine when I used binary mode but it doesn't work whn I use binary mode for file handling

 

Link to comment
Share on other sites

Link to post
Share on other sites

Have you tried opening it as utf-8 e.g.

 

with open('file.txt', 'r', encoding='utf-8') as f:
  print(f.read())

And make sure the file is encoded as utf-8

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×