[Tutor] Re: Tutor digest, Vol 1 #313 - 8 msgs

W.W. van den Broek vdbroekw@wxs.nl
Sat, 20 May 2000 18:26:06 +0200


tutor-request@python.org wrote:
> =

> Send Tutor mailing list submissions to
>         tutor@python.org
> =

> To subscribe or unsubscribe via the World Wide Web, visit
>         http://www.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>         tutor-request@python.org
> =

> You can reach the person managing the list at
>         tutor-admin@python.org
> =

> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
> =

> Today's Topics:
> =

>   1. Global Regular Expressions? (Brian Wisti)
>   2. Regular Expressions part 2 (Brian Wisti)
>   3. RE: Regular Expressions part 2 (Charlie Derr)
>   4. RE: Regular Expressions part 2 (Brian Wisti)
>   5. I need to go home (Last regex mystery solved) (Brian Wisti)
>   6. Re: Regular Expressions part 2 (Michael P. Reilly)
>   7. RE: Regular Expressions part 2 (Charlie Derr)
>   8. Window titles in Tkinter (=3D?iso-8859-1?Q?Mart=3DEDn_Pozzi?=3D)
> =

> --__--__--
> =

> Message: 1
> From: "Brian Wisti" <bwisti@hotmail.com>
> To: tutor@python.org
> Date: Fri, 19 May 2000 13:23:33 PDT
> Subject: [Tutor] Global Regular Expressions?
> =

> Hi all,
> =

> I'm sure that this is just staring me in the face, but I can't figure o=
ut
> how to step through a string with a regular expression.  I know how I w=
ant
> to do this in Perl.  How about I show you what I mean in Perl?
> =

> -- Perl Code --
> #!/usr/bin/env perl
> =

> # A simple example of the strings I'm looking at.
> my $string =3D "<td>item1</td> <td>item2</td><td>item3</td>";
> =

> # Find the text within each table cell, and show each match
> while ($string =3D~ m!<td>(.+?)</td>!g) {
>         print "Matched: ", $1, "\n";
> }
> =

> print "All done!\n";
> -- End of Code --
> =

> So how do I say it in Python?  Would I be able to use a while loop, or =
is
> there some other construct (splitting, or whatever) that I should be us=
ing?
> =

> Thanks ahead of time for any ideas,
> Brian Wisti
> bwisti@hotmail.com
> _______________________________________________________________________=
_
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.co=
m
> =

> --__--__--
> =

> Message: 2
> From: "Brian Wisti" <bwisti@hotmail.com>
> To: tutor@python.org
> Date: Fri, 19 May 2000 15:46:19 PDT
> Subject: [Tutor] Regular Expressions part 2
> =

> Hi all,
> =

> Okay, so I figured out that re.findall() does a global search.  Well an=
d
> good.
> =

> Now I am on to a new strangeness.  Although I can print out the resulti=
ng
> list, and use "for item in matches" to step through the list, I cannot =
use
> array notation to access the list that results from a re.findall().
> =

> For some strange reason, this thing that looks like an array (it even h=
as a
> length of 2) tells me about "list index out of range" when I try to acc=
ess
> matches[0].
> =

> Umm... what am I missing now?
> =

> Thanks,
> Brian Wisti
> bwisti@hotmail.com
> _______________________________________________________________________=
_
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.co=
m
> =

> --__--__--
> =

> Message: 3
> From: "Charlie Derr" <charlie@intelligenesis.net>
> To: "Brian Wisti" <bwisti@hotmail.com>, <tutor@python.org>
> Subject: RE: [Tutor] Regular Expressions part 2
> Date: Fri, 19 May 2000 19:00:52 -0400
> charset=3D"iso-8859-1"
> =

> I think you need to post your code.
> =

> I tried what you said and it worked for me:
> =

> >>> import re
> >>> g =3D "bbbbbbkkdkdkdkdk"
> >>> r =3D re.findall('b',g)
> >>> type(r)
> <type 'list'>
> >>> r
> ['b', 'b', 'b', 'b', 'b', 'b']
> >>> len(r)
> 6
> >>> r[0]
> 'b'
> >>>
> =

> |-----Original Message-----
> |From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf =
Of
> |Brian Wisti
> |Sent: Friday, May 19, 2000 6:46 PM
> |To: tutor@python.org
> |Subject: [Tutor] Regular Expressions part 2
> |
> |
> |Hi all,
> |
> |Okay, so I figured out that re.findall() does a global search.  Well a=
nd
> |good.
> |
> |Now I am on to a new strangeness.  Although I can print out the result=
ing
> |list, and use "for item in matches" to step through the list, I cannot=
 use
> |array notation to access the list that results from a re.findall().
> |
> |For some strange reason, this thing that looks like an array (it
> |even has a
> |length of 2) tells me about "list index out of range" when I try to ac=
cess
> |matches[0].
> |
> |Umm... what am I missing now?
> |
> |Thanks,
> |Brian Wisti
> |bwisti@hotmail.com
> |______________________________________________________________________=
__
> |Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.c=
om
> |
> |
> |_______________________________________________
> |Tutor maillist  -  Tutor@python.org
> |http://www.python.org/mailman/listinfo/tutor
> |
> =

> --__--__--
> =

> Message: 4
> From: "Brian Wisti" <bwisti@hotmail.com>
> To: charlie@intelligenesis.net, tutor@python.org
> Subject: RE: [Tutor] Regular Expressions part 2
> Date: Fri, 19 May 2000 16:36:14 PDT
> =

> Charlie,
> =

> Thanks for responding so quickly.  The original code is a little intric=
ate
> (going crazy on the OO stuff), but here is the least contrived facsmile=
 I
> can come up with.
> =

> -- Begin Python Mystery Meat --
> import re
> =

> sampleString =3D "<td><b>SPAM</b></td><td>eggs</td>"
> resultFormat =3D re.compile(r'<td>(.+?)</td>')
> =

> detailItems =3D resultFormat.findall(result)
> print len(detailItems)
> print type(detailItems)
> print detailItems
> =

> # This is the line that chokes
> print detailItems[0]
> =

> --End of Mystery Meat--
> =

> >From: "Charlie Derr" <charlie@intelligenesis.net>
> >To: "Brian Wisti" <bwisti@hotmail.com>, <tutor@python.org>
> >Subject: RE: [Tutor] Regular Expressions part 2
> >Date: Fri, 19 May 2000 19:00:52 -0400
> >
> >I think you need to post your code.
> >
> >I tried what you said and it worked for me:
> >
> > >>> import re
> > >>> g =3D "bbbbbbkkdkdkdkdk"
> > >>> r =3D re.findall('b',g)
> > >>> type(r)
> ><type 'list'>
> > >>> r
> >['b', 'b', 'b', 'b', 'b', 'b']
> > >>> len(r)
> >6
> > >>> r[0]
> >'b'
> > >>>
> >
> _______________________________________________________________________=
_
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.co=
m
> =

> --__--__--
> =

> Message: 5
> From: "Brian Wisti" <bwisti@hotmail.com>
> To: tutor@python.org
> Date: Fri, 19 May 2000 16:39:30 PDT
> Subject: [Tutor] I need to go home (Last regex mystery solved)
> =

> Hi everybody,
> =

> I got it figured out... I forgot to check for an empty set.  You know, =
no
> match?  As soon as I put that check in, it worked like a charm.
> =

> Sorry to fill people's time with what amounted to a silly mistake.
> =

> Thanks,
> Brian
> _______________________________________________________________________=
_
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.co=
m
> =

> --__--__--
> =

> Message: 6
> From: "Michael P. Reilly" <arcege@shore.net>
> Subject: Re: [Tutor] Regular Expressions part 2
> To: charlie@intelligenesis.net (Charlie Derr)
> Date: Fri, 19 May 2000 19:52:47 -0400 (EDT)
> Cc: bwisti@hotmail.com (Brian Wisti), tutor@python.org
> Reply-To: arcege@shore.net
> =

> > I think you need to post your code.
> >
> > I tried what you said and it worked for me:
> >
> > >>> import re
> > >>> g =3D "bbbbbbkkdkdkdkdk"
> > >>> r =3D re.findall('b',g)
> > >>> type(r)
> > <type 'list'>
> > >>> r
> > ['b', 'b', 'b', 'b', 'b', 'b']
> > >>> len(r)
> > 6
> > >>> r[0]
> > 'b'
> > >>>
> =

> Using findall is well and good.. but it doesn't give context to what is=

> found, just "these are the strings found".  What is probably more
> useful is retrieving the match objects and using those:
> =

> Python 1.5.2 (#2, May 11 1999, 17:14:37)  [GCC 2.7.2.1] on freebsd3
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import re
> >>> s =3D 'bbbbbbkkdkdkdkdk'
> >>> r =3D re.findall('b', s)
> >>> r
> ['b', 'b', 'b', 'b', 'b', 'b']
> >>> type(r[0])
> <type 'string'>
> >>> p =3D re.compile('b')
> >>> i =3D 0
> >>> while i < len(s):
> ...   m =3D p.match(s, i)
> ...   if not m: # no match found
> ...     break
> ...   (st, ed) =3D (m.start(0), m.end(0))
> ...   print (st, ed), m.string[st:ed]
> ...   i =3D ed
> ...
> (0, 1) b
> (1, 2) b
> (2, 3) b
> (3, 4) b
> (4, 5) b
> (5, 6) b
> >>>
> =

> The first returns just strings, going through the loop can get the
> positions inside the strings.  It's fairly easy to abstract this into
> something like findall, but I'll leave that as an exercise.
> =

>   -Arcege
> =

> --
> -----------------------------------------------------------------------=
-
> | Michael P. Reilly, Release Engineer | Email: arcege@shore.net        =
|
> | Salem, Mass. USA  01970             |                                =
|
> -----------------------------------------------------------------------=
-
> =

> --__--__--
> =

> Message: 7
> From: "Charlie Derr" <charlie@intelligenesis.net>
> To: "Brian Wisti" <bwisti@hotmail.com>, <tutor@python.org>
> Subject: RE: [Tutor] Regular Expressions part 2
> Date: Fri, 19 May 2000 20:00:57 -0400
> charset=3D"iso-8859-1"
> =

> Brian,
>         It still works for me :-]
> =

> >>>sampleString =3D "<td><b>SPAM</b></td><td>eggs</td>"
> >>> resultFormat =3D re.compile(r'<td>(.+?)</td>')
> >>> detailItems =3D resultFormat.findall(result)
> Traceback (innermost last):
>   File "<pyshell#16>", line 1, in ?
>     detailItems =3D resultFormat.findall(result)
> NameError: result
> >>> detailItems =3D resultFormat.findall(sampleString)
> >>> print len(detailItems)
> 2
> >>> print type(detailItems)
> <type 'list'>
> >>> print detailItems
> ['<b>SPAM</b>', 'eggs']
> >>> print detailItems[0]
> <b>SPAM</b>
> >>>
> =

> as you can see, i assumed result was a typo and replaced it with
> sampleString
> =

> at this point i'm at a loss as to why you're having problems
> =

> does this same code choke if you enter it into an interpreter like i am=

> doing?
> =

>         good luck,
>                 ~c
> =

> |-----Original Message-----
> |From: Brian Wisti [mailto:bwisti@hotmail.com]
> |Sent: Friday, May 19, 2000 7:36 PM
> |To: charlie@intelligenesis.net; tutor@python.org
> |Subject: RE: [Tutor] Regular Expressions part 2
> |
> |
> |Charlie,
> |
> |Thanks for responding so quickly.  The original code is a little intri=
cate
> |(going crazy on the OO stuff), but here is the least contrived facsmil=
e I
> |can come up with.
> |
> |-- Begin Python Mystery Meat --
> |import re
> |
> |sampleString =3D "<td><b>SPAM</b></td><td>eggs</td>"
> |resultFormat =3D re.compile(r'<td>(.+?)</td>')
> |
> |detailItems =3D resultFormat.findall(result)
> |print len(detailItems)
> |print type(detailItems)
> |print detailItems
> |
> |# This is the line that chokes
> |print detailItems[0]
> |
> |--End of Mystery Meat--
> |
> |>From: "Charlie Derr" <charlie@intelligenesis.net>
> |>To: "Brian Wisti" <bwisti@hotmail.com>, <tutor@python.org>
> |>Subject: RE: [Tutor] Regular Expressions part 2
> |>Date: Fri, 19 May 2000 19:00:52 -0400
> |>
> |>I think you need to post your code.
> |>
> |>I tried what you said and it worked for me:
> |>
> |> >>> import re
> |> >>> g =3D "bbbbbbkkdkdkdkdk"
> |> >>> r =3D re.findall('b',g)
> |> >>> type(r)
> |><type 'list'>
> |> >>> r
> |>['b', 'b', 'b', 'b', 'b', 'b']
> |> >>> len(r)
> |>6
> |> >>> r[0]
> |>'b'
> |> >>>
> |>
> |______________________________________________________________________=
__
> |Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.c=
om
> |
> =

> --__--__--
> =

> Message: 8
> From: "=3D?iso-8859-1?Q?Mart=3DEDn_Pozzi?=3D" <martinpozzi@yahoo.com>
> To: <tutor@python.org>
> Date: Sat, 20 May 2000 11:47:28 -0300
> charset=3D"iso-8859-1"
> Subject: [Tutor] Window titles in Tkinter
> =

> Dear friends,
> =

> I am new to Python, and I am very excited about this wonderful language=
! I
> am using
> Python + Tkinter in Windows, but it seems I can't change the window's t=
itle,
> which reads "tk". I ran Alan's 'case of study' and though he put "Gramm=
ar
> checker" as a title to the window, it just shows up as "tk". Anyone can=

> help? Thanks a lot...
> =

> By the way, though I'm not an expert in Python -as you'd have noticed- =
I
> speak Spanish so I can do my best to help those with little knowledge o=
f
> English. In case it becomes tough for me to answer, I can translate the=

> questions. Buena suerte para todos!
> =

> Mart=EDn Pozzi (martinpozzi@yahoo.com)
> =

> __________________________________________________
> Do You Yahoo!?
> Talk to your friends online with Yahoo! Messenger.
> http://im.yahoo.com
> =

> --__--__--
> =

> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor
> =

> End of Tutor Digest_______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor
Hi =

I am using python on suse 6.3, cannot find the python command for
executing scripts. Tried /user/bin, /usr/sbin, /usr/local/bin,
/usr/local/sbin, /usr/bin/env python
Does anybody know were it is on suse 6.3??
Thanks walter
-- =

W.W. van den Broek	e-mail:		vandenbroek@psyd.azr.nl
AZR-Dijkzigt		fax:		010-4633217
afdeling psychiatrie	tel:		010-4639222
Postbus 2040		e-mail		vdbroekw@wxs.nl (thuis)
3000 CA Rotterdam	homepage:	http://home.planet.nl/~vdbroekw