[Tutor] Learning Regular Expressions

boB Stepp robertvstepp at gmail.com
Mon May 30 15:48:44 EDT 2016


On Mon, May 30, 2016 at 12:13 PM, DirkJSoren at gmail.com
<dirkjsoren at gmail.com> wrote:
> Hi bob,
>
> I had used the wrong email address when I wrote to python tutor on this, and
> evidently it
> took a while for the monitors to let it go ahead and be entered in the list,
> so I apologize
> for the delay in my reply.

That's okay.  Note that Tutor is a collaborative learning environment,
so that normally you should send your responses to the whole list, not
just me.  That way we can all learn from what is written.  So I am
sending this to the Tutor list, but not everything as I notice you
sent another response with pretty much everything to Alan and Tutor.

> I continued to mess with it, and it seems or appears that escape '\' was
> being noticed by
> the interpreter despite the fact it is in a triple quoted area!
>
> As for the traceback, (I am not sure what you mean by 'FULL TRACEBACK'),
> there was no
> highlighted point in the program. I simply got the message I printed here.

I am back at home now with access to Python 3.  What I meant was, if I
have this Python file, test_traceback.py:

#!/usr/bin/env python3

print('''I will deliberately use a backslash inside this triple-quote.\''')

When I run this code from the command line, I get:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>e:

E:\>cd /py_projects

E:\py_projects>py test_traceback.py
  File "test_traceback.py", line 5

    ^
SyntaxError: EOF while scanning triple-quoted string literal

This is what I mean by a full traceback.  Notice it tells me what line
of my code file where it first encountered a problem.  Just so you
have it in mind, with things involving quotes issues, the actual point
of error might be several lines earlier.  But in this case I kept
things simple to illustrate the point.

Now if you ran my one-line program in the Python interpreter, you
would get a different kind of problem:

Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900
64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
py3: print('''I will deliberately use a backslash inside this triple-quote.\''')
...
...
...
...
...

Notice that every time I hit return in the interpreter, trying to
*run* the code, it would not do so.  Instead, every time I press
<Enter> I get three dots.  This is because in my actual code it sees
the second triple-quote as being two single-quotes and a parenthesis.
It does not see the triple-quote as yet being completed, and,
additionally, it does not see the print function as being closed.  So
if I do these completions, I get:

py3: print('''I will deliberately use a backslash inside this triple-quote.\''')
...
...
...
...
... '
...
...
... '''
... )
I will deliberately use a backslash inside this triple-quote.''')




'



py3:

Notice the extra single-quote I threw in.  I hope it shows in more
detail what is going on.

HTH!

boB


More information about the Tutor mailing list