What RE would i use to match this whole word?

Cliff Crawford cjc26 at nospam.cornell.edu
Sun Jul 29 10:53:02 EDT 2001


* G. Willoughby <thecalm at NOSPAM.btinternet.com> menulis:
| this is the code im using for a 'file file' kinda program:
| 
| [snip]
| 
| def search(resultPane, dir, files):
|     searchString = re.compile(str(entryField.get()), re.IGNORECASE) # Get
| search string
|     for file in files:
|         if searchString.search(file) == "None":

None is *not* a string, it's a unique object.  Since search() never
returns a string, your comparison always fails and your else: branch
always gets executed no matter what.  Change this line to:

          if searchString.search(file) is None:

or
          if not searchString.search(file):

to make it work.


-- 
Cliff Crawford            http://www.sowrong.org/
A sign should be posted over every campus toilet:
"This flush comes to you by courtesy of capitalism." 
                                 -- Camille Paglia



More information about the Python-list mailing list