Umlaute in Python darstellen.

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
Nothelion
User
Beiträge: 5
Registriert: Samstag 4. Februar 2023, 14:08

Moin.

Ich habe gerade ein Problem Umlaute in Python darzustellen und weiß einfach nicht, wieso es nicht klappt.

Windows 10
Python 3.10.9
Visual Studio 22 Community Edition
Standartformat ist UTF-8

Code: Alles auswählen

C:\Users\Christoph>python
Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec  6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.getdefaultencoding())
utf-8
>>>

Code: Alles auswählen

# -*- coding: utf-8 -*-
print("Hauptmenü")
Hier der Error:

Code: Alles auswählen

Traceback (most recent call last):
  File "C:\Users\Christoph\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\Christoph\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy\__main__.py", line 39, in <module>
    cli.main()
  File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 320, in run_path
    code, fname = _get_code_from_file(run_name, path_name)
  File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 294, in _get_code_from_file
    code = compile(f.read(), fname, 'exec')
  File "C:\Users\Christoph\source\repos\PythonApplication2023\PythonApplication2023\PythonApplication2023.py", line 1
    print("Hauptmen�")
                     ^
SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xfc in position 8: invalid start byte
Der Fehler besteht mit oder ohne # -*- coding: utf-8 -*-
Benutzeravatar
sparrow
User
Beiträge: 4165
Registriert: Freitag 17. April 2009, 10:28

Die erste Zeile ist in Python3 unnötig, wenn man denn die Datei UTF-8 speichert. Das tust du anscheinend nicht.
Nothelion
User
Beiträge: 5
Registriert: Samstag 4. Februar 2023, 14:08

Wie mache ich das denn?
Benutzeravatar
sparrow
User
Beiträge: 4165
Registriert: Freitag 17. April 2009, 10:28

Ich kenne Visual Studio nicht. Bei den meisten Editoren sieht man unten in der Statusleiste das Encoding der aktuellen Datei und kann es dort auch ändern.
Nothelion
User
Beiträge: 5
Registriert: Samstag 4. Februar 2023, 14:08

ist wahrscheinlich eine Einstellung bei Visual, wo ich nicht durchsteige. Habe mir eben Pycharm geladen und da geht es ohne Probleme.. Danke
Antworten