Re: [Tutor] Help with re in Python 3

2011-11-05 Thread Andreas Perstinger
On 2011-11-04 20:59, Albert-Jan Roskam wrote: It seems that you are not opening the file properly. You could do f = file('///Users/joebatt/Desktop/python3.txt','r') or: withfile('///Users/joebatt/Desktop/python3.txt','r') as f: OP is using Python 3, where "file" is removed. Thus, you have to us

Re: [Tutor] Help with re in Python 3

2011-11-04 Thread Steven D'Aprano
Prasad, Ramit wrote: m = re.search("[A-Z]{3}[a-z][A-Z]{3}", line) That is the expression I would suggest, except it is still more efficient to use a compiled regular expression like the original version. Not necessarily. The Python regex module caches recently used regex strings, avoiding re

Re: [Tutor] Help with re in Python 3

2011-11-04 Thread Prasad, Ramit
>m = re.search("[A-Z]{3}[a-z][A-Z]{3}", line) That is the expression I would suggest, except it is still more efficient to use a compiled regular expression like the original version. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX

Re: [Tutor] Help with re in Python 3

2011-11-04 Thread Albert-Jan Roskam
m, and public health, what have the Romans ever done for us? ~~ > >From: Joe Batt >To: tutor@python.org >Sent: Friday, November 4, 2011 8:42 PM >Subject: [Tutor] Help with re in Py

Re: [Tutor] Help with re in Python 3

2011-11-04 Thread Joel Goldstick
On Fri, Nov 4, 2011 at 3:42 PM, Joe Batt wrote: > Hi all, > Still trying with Python and programming in general…. > > I am trying to get a grip with re. I am writing a program to open a text > file and scan it for exactly 3 uppercase letters in a row followed by a > lowercase followed by exactly

[Tutor] Help with re in Python 3

2011-11-04 Thread Joe Batt
Hi all,Still trying with Python and programming in general…. I am trying to get a grip with re. I am writing a program to open a text file and scan it for exactly 3 uppercase letters in a row followed by a lowercase followed by exactly 3 uppercase letters. ( i.e. oooXXXoXXXooo )If possible co