Re: Regex Python Help

2015-03-26 Thread Denis McMahon
On Wed, 25 Mar 2015 14:19:39 -0700, Gregg Dotoli wrote: > On Wednesday, March 25, 2015 at 4:36:01 PM UTC-4, Denis McMahon wrote: >> On Tue, 24 Mar 2015 11:13:41 -0700, gdotoli wrote: >> >> > I am creating a tool to search a filesystem for one simple string. >> >> man grep >> >> STOP! REINVENTIN

Re: Regex Python Help

2015-03-25 Thread Terry Reedy
On 3/25/2015 7:10 PM, Steven D'Aprano wrote: Does Windows shell have grep? How about Powershell? No. I just use Idle's grep (Find in Files). And I generally would even if Command Prompt did have grep. Idle's has the nice feature that output goes in an Output Window, with each line found p

Re: Regex Python Help

2015-03-25 Thread Mark Lawrence
On 25/03/2015 23:10, Steven D'Aprano wrote: On Thu, 26 Mar 2015 08:19 am, Gregg Dotoli wrote: Grep is regular expressions. If I'm using Python, I'll use the Python modules. Silly It very well may be silly. You're using Python regular expressions because you're using Python. Why are you using

Re: Regex Python Help

2015-03-25 Thread Steven D'Aprano
On Thu, 26 Mar 2015 08:19 am, Gregg Dotoli wrote: > Grep is regular expressions. If I'm using Python, I'll use the Python > modules. Silly It very well may be silly. You're using Python regular expressions because you're using Python. Why are you using Python? Early in this thread you said "H

Re: Regex Python Help

2015-03-25 Thread Mark Lawrence
On 25/03/2015 21:19, Gregg Dotoli wrote: Grep is regular expressions. If I'm using Python, I'll use the Python modules. Silly Gregg Clear as mud, and please don't top post. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrenc

Re: Regex Python Help

2015-03-25 Thread Gregg Dotoli
Grep is regular expressions. If I'm using Python, I'll use the Python modules. Silly Gregg On Wednesday, March 25, 2015 at 4:36:01 PM UTC-4, Denis McMahon wrote: > On Tue, 24 Mar 2015 11:13:41 -0700, gdotoli wrote: > > > I am creating a tool to search a filesystem for one simple string. > > man

Re: Regex Python Help

2015-03-25 Thread Denis McMahon
On Tue, 24 Mar 2015 11:13:41 -0700, gdotoli wrote: > I am creating a tool to search a filesystem for one simple string. man grep STOP! REINVENTING! THE! WHEEL! Your new wheel will invariably be slower and less efficient than the old one. -- Denis McMahon, denismfmcma...@gmail.com -- https:/

Re: Regex Python Help

2015-03-25 Thread Gregg Dotoli
No worries Steven, Thanks to ALL on this thread. Gregg On Tuesday, March 24, 2015 at 9:43:58 PM UTC-4, Steven D'Aprano wrote: > On Wed, 25 Mar 2015 05:13 am, gdot...@gmail.com wrote: > > > The error is: > > > > SyntaxError: Missing parentheses in call to 'print' > > > I cannot imagine how

Re: Regex Python Help

2015-03-24 Thread Steven D'Aprano
On Wed, 25 Mar 2015 05:13 am, gdot...@gmail.com wrote: > The error is: > > SyntaxError: Missing parentheses in call to 'print' I cannot imagine how the message could be more explicit: the call to print is missing parentheses. If you're not going to read the error messages you are given, you are

Re: Regex Python Help

2015-03-24 Thread Gregg Dotoli
Here you go. Windows shell was easier!!! for /f %a in (c:\gonow) do echo %a | c:\Python34\python c:\python34\unopy.py %a Now I can use any regex pattern, I need. On Tuesday, March 24, 2015 at 3:54:25 PM UTC-4, Rob Gaddi wrote: > On Tue, 24 Mar 2015 12:43:38 -0700, Gregg Dotoli wrote: > > > [c

Re: Regex Python Help

2015-03-24 Thread Terry Reedy
On 3/24/2015 2:13 PM, gdot...@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) listdir is not recursive, so this code will

Re: Regex Python Help

2015-03-24 Thread Rob Gaddi
On Tue, 24 Mar 2015 12:43:38 -0700, Gregg Dotoli wrote: > [context snipped due to top posting] > > All I need is a loop, should I bag Python and use a simple shell for loop? Honestly, yes. You're not even using a regular expression, just a fixed string you're trying to search for. You can do

Re: Regex Python Help

2015-03-24 Thread Vincent Vande Vyvre
Le 24/03/2015 20:22, Gregg Dotoli a écrit : Thank you! But The print error is gone, but now the script quickly finishes and doesnt walk the OS tree or search. Gregg On Tuesday, March 24, 2015 at 2:14:32 PM UTC-4, Gregg Dotoli wrote: I am creating a tool to search a filesystem for one simple

Re: Regex Python Help

2015-03-24 Thread Gregg Dotoli
This works fine , but I have to pipe the filename to the script python stool 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)

Re: Regex Python Help

2015-03-24 Thread Rob Gaddi
On Tue, 24 Mar 2015 12:10:24 -0700, Gregg Dotoli wrote: > > 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 u

Re: Regex Python Help

2015-03-24 Thread Skip Montanaro
On Tue, Mar 24, 2015 at 2:22 PM, Gregg Dotoli wrote: > The print error is gone, but now the script quickly finishes and doesnt > walk > the OS tree or search. > You need to walk the directory tree recursively. Take a look at os.walk(). Skip -- https://mail.python.org/mailman/listinfo/python-li

Re: Regex Python Help

2015-03-24 Thread Vincent Vande Vyvre
Le 24/03/2015 20:38, Vincent Vande Vyvre a écrit : Le 24/03/2015 20:22, Gregg Dotoli a écrit : Thank you! But The print error is gone, but now the script quickly finishes and doesnt walk the OS tree or search. Gregg On Tuesday, March 24, 2015 at 2:14:32 PM UTC-4, Gregg Dotoli wrote: I am

Re: Regex Python Help

2015-03-24 Thread Gregg Dotoli
Thank you! But The print error is gone, but now the script quickly finishes and doesnt walk the OS tree or search. Gregg On Tuesday, March 24, 2015 at 2:14:32 PM UTC-4, Gregg Dotoli wrote: > I am creating a tool to search a filesystem for one simple string. > I cannot get the syntax correct.

Re: Regex Python Help

2015-03-24 Thread Gregg Dotoli
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. Th

Re: Regex Python Help

2015-03-24 Thread Gary Herron
On 03/24/2015 11:13 AM, gdot...@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.pat

Re: Regex Python Help

2015-03-24 Thread Skip Montanaro
On Tue, Mar 24, 2015 at 1:13 PM, wrote: > SyntaxError: Missing parentheses in call to 'print' It appears you are attempting to use a Python 2.x print statement with Python 3.x Try changing the last line to print(line.rstrip()) Skip -- https://mail.python.org/mailman/listinfo/python-list