views:

34

answers:

1

First of all, I get the name of the current window

win32gui.GetWindowText(win32gui.GetForegroundWindow())

k, no problem with that...

But now, how can I make an if with the result for having an specific string on it...

For example, the result gave me

C:/Python26/

How can I make an True of False for the result containing the word, 'python' ?

I'm trying with re.search, but I'm not being able to make it do it

A: 

python is not the same as Python. You probably need to pass re.IGNORECASE to enable case-insensitive matching. Example:

title = win32gui.GetWindowText(win32gui.GetForegroundWindow())
if re.search(title, "python", re.IGNORECASE):
    print "Found it!"

However, if you don't need the power of regexes, it is simpler and faster to do a simple string search:

if title.lower().find("python") >= 0:
Thomas
Or `if "python" in title.lower(): ...`
tgray