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.

0

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

1

You can simply use the in keyword, like so:

if 'Word' in myfile:
    print myfile

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.