Regex Python Help

Gregg Dotoli gdotoli at gmail.com
Tue Mar 24 15:10:24 EDT 2015


Thank you Gary, that got rid of the error, but now there is no tree walk, it runs and immediatley finishes. I just need to grep each file. I have this working with the windows "for /r %a and redirecting that to Python, but want to use Python only. I do have dummy files with the regex string.

Thanks again,
Gregg




On Tuesday, March 24, 2015 at 2:34:20 PM UTC-4, Gary Herron wrote:
> On 03/24/2015 11:13 AM, gdotoli at gmail.com wrote:
> > I am creating a tool to search a filesystem for one simple string.
> > I cannot get the syntax correct.
> > Thank you in advance for your help.
> >
> > import sys
> > import re
> > import os
> > path='/'
> > viewfiles=os.listdir(path)
> > for allfiles in viewfiles:
> >      file= os.path.join(path, allfiles)
> > text=open(file, "r")
> > for line in text:
> >      if re.match("DECRYPT_I", line):
> >          print line,
> >
> > ----------------------------------------------------------
> > This should search every file for the simple regex "DECRYPT_I"
> > This is from the root down.
> >
> > The error is:
> >
> > SyntaxError: Missing parentheses in call to 'print'
> >
> > Please help.
> > Gregg Dotoli
> 
> You appear to be using Python3, but have written code for Python2.
> 
> There are a number of differences between the two, but your particular 
> error runs into the different syntax for prints.
> 
> Python2: print line # This is a statement
> Python3  print(line)  # This is a procedure call
> 
> 
> 
> -- 
> Dr. Gary Herron
> Department of Computer Science
> DigiPen Institute of Technology
> (425) 895-4418




More information about the Python-list mailing list