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 - [email protected]
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 - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
[Tutor] subprocess module seems to be failing...
Running Linux Mint 17.3
Python3.4.3
I'm following a Tutor concerning the subprocess module which said to
open a Terminal SHELL and type:
$ python3
>>> import subprocess
>>> subprocess.call('ls', shell=True)
Last night the subprocess.call portion was erroring saying their was no
'call' attribute. I tried asking
dir(subprocess) and call wasn't listed there. I figured I would try
again this morning, however, this
is what I was greeted with shortly after booting up and launching my
Terminal:
[justme@ispy] ~$ python3
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import subprocess
Traceback (most recent call last):
File "", line 1, in
File "/home/justme/python_work/subprocess.py", line 39
^
SyntaxError: EOF while scanning triple-quoted string literal
>>>
Seems like the module is deteriorating or something, as yesterday it
accepted the import command
to include it! :)
I found a subprocess.py in /usr/lib/python3.4 and grabbed it with gedit
and looked at it line by line. It has tripple double quotes but also
single double quotes throughout it in places, but they all seemed to
have a companion quote to offset them...and the entire text area is one
solid color which would seem to indicate
it is being ignored by python...
What should I do now?
Thanks!
___
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] subprocess module seems to be failing...
Add sound of me beating my head with a bat! :) Thanks Peter! -I was a bit too precise in my naming conventions for later review! On 06/03/2016 02:30 PM, Peter Otten wrote: [email protected] wrote: Running Linux Mint 17.3 Python3.4.3 I'm following a Tutor concerning the subprocess module which said to open a Terminal SHELL and type: $ python3 >>> import subprocess >>> subprocess.call('ls', shell=True) Last night the subprocess.call portion was erroring saying their was no 'call' attribute. I tried asking dir(subprocess) and call wasn't listed there. I figured I would try again this morning, however, this is what I was greeted with shortly after booting up and launching my Terminal: [justme@ispy] ~$ python3 Python 3.4.3 (default, Oct 14 2015, 20:28:29) [GCC 4.8.4] on linux Type "help", "copyright", "credits" or "license" for more information. >>> >>> import subprocess Traceback (most recent call last): File "", line 1, in File "/home/justme/python_work/subprocess.py", line 39 Look carefully at the line above. You wrote a script and called it subprocess.py. Bad idea ;) Delete or rename your subprocess.py, and the one in the standard library will become visible again and work as smoothly as ever. ^ SyntaxError: EOF while scanning triple-quoted string literal >>> Seems like the module is deteriorating or something, as yesterday it accepted the import command to include it! :) I found a subprocess.py in /usr/lib/python3.4 and grabbed it with gedit and looked at it line by line. It has tripple double quotes but also single double quotes throughout it in places, but they all seemed to have a companion quote to offset them...and the entire text area is one solid color which would seem to indicate it is being ignored by python... What should I do now? Thanks! ___ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] printing items form list
On 03/03/2017 12:19 PM, Alan Gauld via Tutor wrote:
On 03/03/17 18:52, Peter Otten wrote:
Antonio Zagheni via Tutor wrote:
suitcase = ["book, ", "towel, ", "shirt, ", "pants"]
Hm, looks like you opened Rafael's suitcase while he wasn't looking, and
sneaked in some commas and spaces ;)
That's cheating...
Its also very difficult to maintain since if you add
new items to the suitcase you need to make sure they
all have commas except the last one. And inconsistent data formatting in
a list is a nightmare.
For example, what happens if you decide to sort the list,
the last item is no longer last and the commas are all
messed up.
That's one reason why join() is a better solution, it
handles all of that for you. It's also faster, although
in a small application you'd never notice the difference.
The ','.join(suitcase) is obviously best of all, but if one doesn't know
that method, the below suggestion can be fixed with:
suitcase = ['book', 'towel', 'shirt', 'pants']
for i in suitcase:
st = st + i + ', '
print('You have a s% in your luggage.' % st)
___
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
