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

Format error. #2874

Closed
Independent-X opened this issue Aug 22, 2021 · 7 comments
Closed

Format error. #2874

Independent-X opened this issue Aug 22, 2021 · 7 comments
Labels
can't reproduce A developer couldn't reproduce the issue waiting for information

Comments

@Independent-X
Copy link

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.

@elextr
Copy link
Member

elextr commented Aug 22, 2021

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)

@elextr elextr added can't reproduce A developer couldn't reproduce the issue waiting for information labels Aug 22, 2021
@eht16
Copy link
Member

eht16 commented Aug 22, 2021

The posted error message rather indicates a problem with your Python code.
Without the file in question, it's hard to help.

@Independent-X
Copy link
Author

Independent-X commented Aug 28, 2021

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


------------------
(program exited with code: 1)

@elextr
Copy link
Member

elextr commented Aug 28, 2021

@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.

@nomadbyte
Copy link
Contributor

nomadbyte commented Sep 9, 2021

Adding to what @elextr mentioned, the default encoding (for new files) is actually set in menu Edit > Preferences: Files (Encodings)

@xiota
Copy link
Contributor

xiota commented Nov 20, 2021

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.

@elextr
Copy link
Member

elextr commented Nov 20, 2021

Closed as no response, @Independent-X if you answer the questions asked in various comments above it can be re-opened if necessary.

@elextr elextr closed this as completed Nov 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can't reproduce A developer couldn't reproduce the issue waiting for information
Projects
None yet
Development

No branches or pull requests

5 participants