Re: [Tutor] Learning Regular Expressions
Thanks Alan I noticed that I was using some double ' to encircle some things and some single ' for apostrophes in contractionsand fixed those...but apparently since you could run it, that part didn't matter. The problem was ultimately caused by a stray ''' which was a fragment of me messing with things trying to fix them and it slipped down my screen and was hidden from me when I would look at the script! Thanks for double checking me. :) On 05/30/2016 03:07 PM, Alan Gauld via Tutor wrote: On 30/05/16 18:21, dirkjso...@gmail.com wrote: I moved my notes that contained any '\'s to a different python file. However, if we run it, we get the error I was having. Here's the script: Runs fine for me. Can you run it using the python command line interpreter rather than IDLE? Do you still get errors? If so cut n paste the full error to the list. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Learning Regular Expressions
Thanks Bob, OK. The escape character \ still is active in escaping the next character or space when inside of triple quotes. So, I guess when the program is running, since I am not printing these things out, I don't care if anything in my notes is escaped unless it is a strategic single or double quotethus disrupting the bubble of the comment formed by such triple quotes. Speaking of single and double quotes, I noticed that I had used two single ' to surround some things, so I changed them to double quotes so as not to confuse my triple quotes. Then I noticed that I had also used contractions with ' apostrophes which would also mess up my comment bubble, so I got rid of those also. As far as I can tell, the triple single quotes (''') should work at that point. In fact, they do if I wrap this whole section in a print( ) statement and paste it into IDLE SHELL. But! I found as soon as I had IDLE run my script I got the same error. Here is where I am at now with this script: (NOTE: I have the final solution below this listing.) #!/usr/bin/env python3 ''' Regular Expressions - or at least some Identifiers: \d any number \D anything but a number (digit) \s space \S anything but a space \w any character \W anything but a character \. any character (or even a period itself if you use \.) except for a newline \a search for just the letter "a" \b the white space around words Modifiers {x}we are expecting "x" number of something {1, 3} we are expecting 1-3 in length of something -, so for digits we write \d{1-3} + means Match 1 or more ? means Match 0 or 1 * Match 0 or more $ Match the end of a string ^ Match the beginning of a string | Match either or - so you might write \d{1-3} | \w{5-6} [ ] a range or "variance" such as [A-Z] or [A-Za-z] Cap 1st letter followed by lower case or [1-5a-qA-Z] starts with a number inclusive of 1-5 then lower case letter then followed by any Cap letter! :) White Space Characters (may not be seen): \n new line \s space \t tab \e escape \f form feed \r return DO NOT FORGET!: . + * ? [ ] $ ^ ( ) { } | \if you really want to use these, you must escape them ''' I was not getting a line number for the error because I was running it only from IDLE and I was looking only at the commented area...as that now was the only thing left in the scriptor was it? It hadn't occurred to me to try the linux command line. When I called it from the Linux Console, I got: [justme@ispy] ~/python_work$ python3 RE-1.py File "RE-1.py", line 69 ^ SyntaxError: EOF while scanning triple-quoted string literal [justme@ispy] ~/python_work$ Which puzzled me, as I didn't have 69 lines! And guess what I found when I scrolled down past the end of my script? Way down out of sight below my program was a single ''' setting down there all by it's lonesome self! -a fragment of me changing things all over the place trying to figure out what was going wrongit had slipped below my line of sight and with further chances continued to work it's way down the page. I think all these fixes...this solves my problem! Thanks for your time and help! :) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Learning Regular Expressions
On 30/05/16 18:21, dirkjso...@gmail.com wrote: > I moved my notes that contained any '\'s to a different python file. > However, if we run it, we get the error I was having. Here's the > script: Runs fine for me. Can you run it using the python command line interpreter rather than IDLE? Do you still get errors? If so cut n paste the full error to the list. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Learning Regular Expressions
On Mon, May 30, 2016 at 12:13 PM, dirkjso...@gmail.comwrote: > 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 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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Learning Regular Expressions
On 05/24/2016 01:48 PM, Alan Gauld via Tutor wrote: On 23/05/16 23:08, Terry--gmail wrote: scripted worked great without the notes! I'd like to know what it is in the below Tripple-Quoted section that is causing me this problem...if anyone recognizes. In IDLE's script file..._it's all colored green_, which I thought meant Python was going to ignore everything between the tripple-quotes! Its all green forv me too and it runs perfectly - as in it does absolutly nothing. And if I add print('hello world') at the end it prionts ok too. I even tried assigning your docsstring to a variable and printing that and it too worked. Linux Mint 17 Python 3.4.3 IDLE 3 So I don't think this is your entire problem. Maybe you should show us some code that actually causes the error? But if I run just the below portion of the script in it's own file, I get the same While Scanning Tripple-Quotes error. As above, it runs silently for me. Hi Alan, I moved my notes that contained any '\'s to a different python file. However, if we run it, we get the error I was having. Here's the script: #!/usr/bin/env python3 ''' Regular Expressions - or at least some Identifiers: \d any number \D anything but a number (digit) \s space \S anything but a space \w any character \W anything but a character . any character (or even a period itself if you use \.) except for a newline a search for just the letter 'a' \b the white space around words Modifiers {x}we are expecting "x" number of something {1, 3} we're expecting 1-3 in length of something -, so for digits we write \d{1-3} + means Match 1 or more ? means Match 0 or 1 * Match 0 or more $ Match the end of a string ^ Match the beginning of a string | Match either or - so you might write \d{1-3} | \w{5-6} [ ] a range or "variance" such as [A-Z] or [A-Za-z] Cap 1st letter followed by lower case or [1-5a-qA-Z] starts with a number inclusive of 1-5 then lower case letter then followed by any Cap letter! :) White Space Characters (may not be seen): \n new line \s space \t tab \e escape \f form feed \r return DON'T FORGET!: . + * ? [ ] $ ^ ( ) { } | \ if you really want to use these, you must escape them '\' ''' ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Learning Regular Expressions
On 23/05/16 23:08, Terry--gmail wrote: > scripted worked great without the notes! I'd like to know what it is in > the below Tripple-Quoted section that is causing me this problem...if > anyone recognizes. In IDLE's script file..._it's all colored green_, > which I thought meant Python was going to ignore everything between the > tripple-quotes! Its all green forv me too and it runs perfectly - as in it does absolutly nothing. And if I add print('hello world') at the end it prionts ok too. I even tried assigning your docsstring to a variable and printing that and it too worked. Linux Mint 17 Python 3.4.3 IDLE 3 So I don't think this is your entire problem. Maybe you should show us some code that actually causes the error? > But if I run just the below portion of the script in > it's own file, I get the same While Scanning Tripple-Quotes error. As above, it runs silently for me. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Learning Regular Expressions
On Mon, May 23, 2016 at 5:08 PM, Terry--gmailwrote: > Running Linux Mint > The YouTube Sentdex Video tutor I am following. > He is working in Python3.4 and I am running Python3.4.3 > > He's demonstrating some Regular Expressions which I wanted to test out. On > these test scripts, for future referrence, I have been putting my notes in > Tripple Quotes and naming the scripts descriptively to be able to find them > again, when I need to review. However, this time, when I copied in a simple > script below my RE notes, and ran it from IDLE (and from Console) I got the > following error: > > SyntaxError: EOF while scanning triple-quoted string literal > > Now, there was also a tripple-quoted string I had set a variable to in my > script...so I thought it was the active part of the script! But eventually, > through the process of elimination, I discovered the scripted worked great > without the notes! I'd like to know what it is in the below Tripple-Quoted > section that is causing me this problem...if anyone recognizes. In IDLE's > script file..._it's all colored green_, which I thought meant Python was > going to ignore everything between the tripple-quotes! But if I run just the > below portion of the script in it's own file, I get the same While Scanning > Tripple-Quotes error. I do not know the exact point of error in your code, but even if you use triple-quoted strings, escape sequences still work. I do not have a Python 3 installation handy, but in the Python 2.7.8 that I do have handy: Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> print ''' \tTab character!!! ''' Tab character!!! >>> Note: I had to simulate with spaces what I see in IDLE as my Gmail refuses to accurately copy my IDLE result. I suspect that your multiple backslash instances are generating what you are observing. Doesn't your full traceback target the exact line of your code on which this occurs? HTH, boB ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Learning Regular Expressions
Running Linux Mint The YouTube Sentdex Video tutor I am following. He is working in Python3.4 and I am running Python3.4.3 He's demonstrating some Regular Expressions which I wanted to test out. On these test scripts, for future referrence, I have been putting my notes in Tripple Quotes and naming the scripts descriptively to be able to find them again, when I need to review. However, this time, when I copied in a simple script below my RE notes, and ran it from IDLE (and from Console) I got the following error: SyntaxError: EOF while scanning triple-quoted string literal Now, there was also a tripple-quoted string I had set a variable to in my script...so I thought it was the active part of the script! But eventually, through the process of elimination, I discovered the scripted worked great without the notes! I'd like to know what it is in the below Tripple-Quoted section that is causing me this problem...if anyone recognizes. In IDLE's script file..._it's all colored green_, which I thought meant Python was going to ignore everything between the tripple-quotes! But if I run just the below portion of the script in it's own file, I get the same While Scanning Tripple-Quotes error. #!/usr/bin/env python3 ''' Regular Expressions - or at least some Identifiers: \d any number \D anything but a number (digit) \s space \S anything but a space \w any character \W anything but a character . any character (or even a period itself if you use \.) except for a newline a search for just the letter 'a' \b the white space around words Modifiers {x}we are expecting "x" number of something {1, 3} we're expecting 1-3 in length of something -, so for digits we write \d{1-3} + means Match 1 or more ? means Match 0 or 1 * Match 0 or more $ Match the end of a string ^ Match the beginning of a string | Match either or - so you might write \d{1-3} | \w{5-6} [ ] a range or "variance" such as [A-Z] or [A-Za-z] Cap 1st letter followed by lower case or [1-5a-qA-Z] starts with a number inclusive of 1-5 then lower case letter then followed by any Cap letter! :) White Space Characters (may not be seen): \n new line \s space \t tab \e escape \f form feed \r return DON'T FORGET!: . + * ? [ ] $ ^ ( ) { } | \ if you really want to use these, you must escape them '\' ''' Thanks for your thoughts! --Terry ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor