[Tutor] Help with re in Python 3

Joel Goldstick joel.goldstick at gmail.com
Fri Nov 4 20:51:38 CET 2011


On Fri, Nov 4, 2011 at 3:42 PM, Joe Batt <joebatt at hotmail.co.uk> 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 3 uppercase letters. ( i.e.  oooXXXoXXXooo )
> If possible could you explain why I am getting "EOL while scanning string
> literal" when I try running the following program in Python 3.
>
> My program:
>
> import re
>
> regexp=re.compile(r"[a-z]"r"[A-Z]"r"[A-Z]"r"[A-Z]"r"[a-z]"r"[A-Z]"r"[A-Z]"r"[A-Z]"r"[a-z])
>
> file=('///Users/joebatt/Desktop/python3.txt','r')
> for line in file.readlines():
>     if regexp.search(line):
>         print("Found value 3 caps followed by lower case followed by 3
> caps")
> file.close()
>
> If possible could you explain why I am getting "EOL while scanning string
> literal" when I try running my program in Python 3.
>
> Thanks for your help
>
> Joe
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
You should read a little more about regular expressions to simplify yours,
but I believe your problem is that you have no closing "
after this: r"[a-z])

change it to r"[a-z]")


-- 
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111104/c3e98a88/attachment.html>


More information about the Tutor mailing list