-1
import os
from fnmatch import fnmatch

root = 'Directory'


for path, subdirs, file in os.walk(root):
for files in file : 
with open(files) as f:
        contents = f.read()
    if 'Search_string' in contents:
print os.path.join(path, files)

It is giving me below error :

    for files in file :
      ^
IndentationError: expected an indented block

Please help.

Carles Mitjans
  • 4,786
  • 3
  • 19
  • 38
Atul D
  • 31
  • 6

1 Answers1

0

Python language totally depends on indentation.You didn't give any indentation in your code.So you should give indentation in your code.You should follow this link for indentation.

Structuring with Indentation.

import os
from fnmatch import fnmatch

root = 'Directory'

for path, subdirs, file in os.walk(root):
    for files in file : 
        with open(files) as f:
            contents = f.read()
            if 'Search_string' in contents:
                print os.path.join(path, files)
Rahul Gupta
  • 504
  • 4
  • 17