0

I'm having error but my output will be save perfectly. How?

this is the output in terminal......

Traceback (most recent call last):
  File "C:\Users\Ankit\Desktop\PYTHON Project\Project App Monitoring\test1.py", line 19, in <module>
    file.write(item + "\n")
  File "C:\Users\Ankit\AppData\Local\Programs\Python\Python310\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-3: character maps to <undefined>

Note that: my output file that i expect to save is properly fine.

this is the program......

import winreg

# Connecting to the registry key
access_registry = winreg.ConnectRegistry(None,winreg.HKEY_LOCAL_MACHINE)
access_key = winreg.OpenKey(access_registry,r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")

# Enumerating all values under the key
output = []
for n in range(winreg.QueryInfoKey(access_key)[0-3]):
    try:
        value = winreg.EnumKey(access_key, n)
        output.append(value)
    except:
        break

# Writing the output to a file
with open("output.txt", "w") as file:
    for item in output:
        file.write(item + "\n")

# Closing the connection
winreg.CloseKey(access_key)
winreg.CloseKey(access_registry)

0 Answers0