file_path = r"C:\Temp\test2.txt" # r prefix for raw string to avoid escape characters with open(file_path, "w") as f: f.write("Hello, world!\n")