#๐ configparser spams chinese characters
16 messages ยท Page 1 of 1 (latest)
@drifting kestrel
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
import os
import configparser
folder = 'C:\\Users\\Yoda\\AppData\\Roaming\\PrismLauncher\\instances'
instances = [name for name in os.listdir(folder) if os.path.isdir(os.path.join(folder, name))]
blacklist = ['.LAUNCHER_TEMP', '.tmp', '1.19.4', '24w13a']
blacklistSet = set(blacklist)
templateCode = "[{name}]\nContainer=MinecraftMenuContainerVisible\nMeter=Image\nImageName={icon}"
for instance in instances:
instanceInBlacklist = instance in blacklistSet
if not instanceInBlacklist:
iconPath = f"C:\\Users\\Yoda\\AppData\\Roaming\\PrismLauncher\\instances\\{instance}\\.minecraft\\icon.png"
if not os.path.isfile(iconPath):
iconPath = f"C:\\Users\\Yoda\\AppData\\Roaming\\PrismLauncher\\instances\\{instance}\\minecraft\\icon.png"
if not os.path.isfile(iconPath):
iconPath = f"C:\\Users\\Yoda\\AppData\\Roaming\\PrismLauncher\\instances\\{instance}\\icon.png"
if not os.path.isfile(iconPath):
print("Icon not found " + iconPath)
iconPath="C:\\Users\\Yoda\\Documents\\Rainmeter\\Skins\\FirstSkin\\@Resources\\Pickaxe64.png"
write_config = configparser.ConfigParser()
write_config.add_section(instance)
write_config.set(instance,"Meter", "Image")
write_config.set(instance,"Container","MinecraftMenuContainerVisible")
write_config.set(instance,"ImageName",iconPath)
write_config.set(instance,"LeftMouseUpAction",f"[C:\\Users\\Yoda\\AppData\\Local\\Programs\\PrismLauncher\\prismlauncher.exe --launch \"{instance}\"]")
inifile = open("C:\\Users\\Yoda\\Documents\\Rainmeter\\Skins\\FirstSkin\\Games Menu\\MainMenu.ini", "a")
write_config.write(inifile)
inifile.close()
the chinese characters are from the file.
The file (a rainmeter ini) is UTF-16 LE according to notepad
that might be an issue
i tried just writing with plain text using open, but it had the same issue
so windows uses UTF-16 apparently, but python opens stuff in utf-8
try passing encoding="utf-16" to every open() function
that worked, thanks so much! I tried to do it before but didn't add the encoding= part as i'm not used to python
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.
๐ configparser spams chinese characters