Python Regular Expression TypeError
Posted
by spaghettiwestern
on Stack Overflow
See other posts from Stack Overflow
or by spaghettiwestern
Published on 2010-06-16T21:35:37Z
Indexed on
2010/06/16
21:42 UTC
Read the original article
Hit count: 161
python
I am writing my first python program and I am running into a problem with regex. I am using regular expression to search for a specific value in a registry key.
import _winreg
import re
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{26A24AE4-039D-4CA4-87B4-2F83216020FF}")
results=[]
v = re.compile(r"(?i)Java")
try:
i = 0
while 1:
name, value, type = _winreg.EnumValue(key, i)
if v.search(value):
results.append((name,value,type))
i += 1
except WindowsError:
print
for x in results:
print "%-50s%-80s%-20s" % x
I am getting the following error:
exceptions.TypeError: expected string or buffer
I can use the "name" variable and my regex works fine. For example if I make the following changes regex doesn't complain:
v = re.compile(r"(?i)DisplayName")
if v.search(name):
Thanks for any help.
© Stack Overflow or respective owner