When I create a new main.py with Geany and save it, it is always saved in ANSI format instead of UTF-8 format.
It always causes an error when I try to test my program if I add any character which isn't an English character to it: SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0x** in position 0: invalid start byte.
Saves as UTF-8 here and Python happily accepts non-ASCII characters.
``` 22:36:50: Geany INFO : Geany 1.38 (git >= b524a58e), en_AU.UTF-8 22:36:50: Geany INFO : GTK 3.24.20, GLib 2.64.6 22:36:50: Geany INFO : OS: Linux Mint 20 (ulyana) ```
The posted error message rather indicates a problem with your Python code. Without the file in question, it's hard to help.
Follow these steps can reproduce the error: 1.Create a new main.py. 2.Delete all the code in it. 3.Write this:
#!/usr/bin/env python # -*- coding: utf-8 -*- print("あ")
4.Save it. 5.Try running it. Here is the result:
File "test.py", line 3 print("��") ^ SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xa4 in position 0: invalid start byte.
@Independent-X what is your locale, and what does the `encoding:` in the status bar show?
To be clear, files are saved with the encoding set in the save dialog (which defaults to what is in the status bar). Users can set what encoding they want a file saved in, and Geany does what it is told, so it will never read the contents of the file to decide an encoding to save a file.
The contents are considered when loading (unless the user explicitly specifies an encoding) because there is no setting available then. That is the only time the `-*- coding:` line is considered.
Adding to what @elextr mentioned, the default encoding (for new files) is actually set in Preferences > Files.
I cannot reproduce this.
* What version of Geany. Have you tried checking whether 1.38 is affected? * What operating system? * What version of Python? Old versions may not handle utf-8 properly.
Closed as no response, @Independent-X if you answer the questions asked in various comments above it can be re-opened if necessary.
Closed #2874.
github-comments@lists.geany.org