Danke!
mit / stattt \ scheint zu funktionieren
Code: Alles auswählen
myFile1 = open('C:/Users/Onri/AppData/Local/Programs/Python/Python38/exersices/my_hope.txt', 'rt', encoding="utf8")
print(myFile1.read())
Danke!
Code: Alles auswählen
myFile1 = open('C:/Users/Onri/AppData/Local/Programs/Python/Python38/exersices/my_hope.txt', 'rt', encoding="utf8")
print(myFile1.read())
Code: Alles auswählen
from pathlib import Path
script_path = Path(__file__).resolve().parent / „relativ.dat“
with open(script_path / 'my_hope.txt', 'rt', encoding="utf8") as f:
print(f.read())
Im ersten Post von __deets__ stand doch schon eine flexible Lösung die mit Pfaden relativ zum Skript arbeitet:
Code: Alles auswählen
pathlib.Path(__file__).resolve().parent / „relativ.dat“
Code: Alles auswählen
from pathlib import Path
script_path = Path(__file__).resolve().parent
print((script_path / "my_hope.txt").read_text(encoding="utf8"))