Ini File Created in AHK In Python Is Unreadable

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
roonyrooxcess
Posts: 61
Joined: 20 Nov 2020, 21:29

Ini File Created in AHK In Python Is Unreadable

16 Nov 2021, 06:23

Hey,

Im trying to read an AHK ini file in python, but its unreadable in python. I know you need some type of encoding to read the ini file in python. But im pretty new to python, so no idea where to start ...

Thanks!

Ive attached the file
DetectPress.ini
(472 Bytes) Downloaded 45 times


Code im using to create the ini file

Code: Select all

IniWrite, 0,  D:\12\Temp\DetectPress.ini, SellLow1, SellLow1
Code in Python

Code: Select all

from pathlib import Path

data_folder = Path("D:/12/Temp/")
file_to_open2=data_folder/"DetectPress.ini"

y2 = open(file_to_open2, "r")

print(y2.read())



DetectPress.ini
(472 Bytes) Downloaded 45 times
User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Ini File Created in AHK In Python Is Unreadable

16 Nov 2021, 06:58

The INI file is in UTF-16 by default. A workaround is below.

Code: Select all

ini = %A_ScriptDir%\DetectPress.ini
FileRecycle, %ini%
FileAppend,, %ini%, CP0
IniWrite, 0,  %ini%, SellLow1, SellLow1
Explained: IniWrite

File encoding of CP0 uses the system default ANSI code page.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada and 170 guests