[Tutor] finding strings in other strings

Daniel Yoo dyoo@hkn.EECS.Berkeley.EDU
Sun, 6 Aug 2000 00:42:04 -0700 (PDT)

On Sat, 5 Aug 2000, Brett wrote:

> 	I was making a little program to rename mp3 files, but didnt want it to 
> effect other files in the same directory.  I tried using something like 
> this to have the program only effect mp3 files:
> files  = os.listdir(os.curdir)
> for x in files:
> 	if 'mp3' in x:

wolfkin@freedomspace.net already mentioned using string.find() to search
for substrings.  Another alternative to string searching is to use the
glob() function within the 'glob' module, which will grab the filenames of
all .mp3 files for you.  For example:

>>> from glob import glob
>>> glob('*.tex')
['foo.tex', 'abstractalgebra.tex']

The 'glob' module is documented here: