9

I want it to find the following file in mylist: "Microsoft Word 105Prt" (this file name could vary but will always have "Word" in it.

for myfile in filelist:
    if myfile.contains("Word"): 
        print myfile

How can I modify this to work in python 2.7.5 since contains doesn't work.

user12059
  • 733
  • 2
  • 13
  • 27

2 Answers2

2

You can substitute find for contains and just check for a return code of something other than -1.

for myfile in filelist:
    if myfile.find("Word")!=-1: 
        print myfile
Sam A
  • 21
  • 1
1

You can simply use the in keyword, like so:

if 'Word' in myfile:
    print myfile
aruisdante
  • 8,875
  • 2
  • 30
  • 37