0

when I prefix my .py file using utf-8 or Latin-1 I always get bad charcacters in OUTPUT or in matplotlib figure text.

Post 'Working with UTF-8 encoding in Python source' does not answer my question which is specific to vs code.

In:

`# -*- coding: utf-8 -*-`
print('à')

Out:

matplotlib text with utf-8 encoding right display > matplotlib text with utf-8 encoding right display

In:

`# -*- coding: Latin-1 -*-`
print('à')

Out:

à

matplotlib text with Latin-1 wrong display > matplotlib text with Latin-1 wrong display

I tried different encodings but I never get proper outputs

2
  • 1
    You face a mojibake case: 'Périodes'.encode( 'utf-8').decode( 'latin1') returns 'Périodes'. Switch to UTF-8 Everywhere Commented Dec 16, 2023 at 10:43
  • maybe your system or editor use latin1 and you have latin-1 in your code. Commented Dec 16, 2023 at 12:27

2 Answers 2

0

In vs code, I've checked Preferences > Settings > code runner : Run in Terminal so I no longer need to use the utf-8 code substitute in the plain text, I can now write "à" or any accentuated letter directly so OUTPUT and matplotlib are OK.

Sign up to request clarification or add additional context in comments.

Comments

0

Thank you JosefZ.

I adopt UTF-8 everywhere.

print('\xc3\xa0') fixed the issue.

print('à'.encode('utf-8')) to find the code.

I you have better solution configuring matplotlib avoiding to use codes, I'll take it.

1 Comment

print('à') should work fine if your editor is really using UTF-8.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.