Re: [Tutor] don't understand iteration

2014-11-13 Thread Steven D'Aprano
On Mon, Nov 10, 2014 at 03:08:23PM -0800, Clayton Kirkwood wrote: > Also of confusion, the library reference says: > > Match objects always have a boolean value of True. Since match() and > search() return None when there is no match, you can test whether there was > a match with a simple if stat

Re: [Tutor] don't understand iteration

2014-11-13 Thread Steven D'Aprano
Coming in late to the conversation: On Sun, Nov 09, 2014 at 04:34:29PM -0800, Clayton Kirkwood wrote: > I have the following code: > > import urllib.request,re,string > months = ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May.', 'Jun.', 'Jul.', 'Aug.', > 'Sep.', 'Oct.', 'Nov.', 'Dec.'] > from urllib.reque

Re: [Tutor] don't understand iteration

2014-11-11 Thread Alex Kleider
On 2014-11-11 06:19, eryksun wrote: On Tue, Nov 11, 2014 at 4:52 AM, Alan Gauld wrote: Python 3 extended unpacking: >>> a, *bcd, e = 'abcde' >>> a 'a' >>> bcd ['b', 'c', 'd'] >>> e 'e' Seeing the above in a recent post, it made me wonder what would happen if

Re: [Tutor] don't understand iteration

2014-11-11 Thread eryksun
On Tue, Nov 11, 2014 at 4:52 AM, Alan Gauld wrote: > On 11/11/14 04:45, Clayton Kirkwood wrote: > *list(range(1,6)) >> >>File "", line 1 >> SyntaxError: can use starred expression only as assignment target > > list() is a function. You cannot unpack a function. > > Also the * operator nee

Re: [Tutor] don't understand iteration

2014-11-11 Thread Alan Gauld
On 11/11/14 04:45, Clayton Kirkwood wrote: *list(range(1,6)) File "", line 1 SyntaxError: can use starred expression only as assignment target list() is a function. You cannot unpack a function. Also the * operator needs to be used inside a function parameter list. (There may be some obsc

Re: [Tutor] don't understand iteration

2014-11-10 Thread Clayton Kirkwood
>-Original Message- >From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On >Behalf Of Alan Gauld >Sent: Monday, November 10, 2014 5:07 PM >To: tutor@python.org >Subject: Re: [Tutor] don't understand iteration > >On 11/11/14 00:28, Clayton Kirk

Re: [Tutor] don't understand iteration

2014-11-10 Thread Clayton Kirkwood
>-Original Message- >From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On >Behalf Of Ben Finney >Sent: Sunday, November 09, 2014 8:25 PM >To: tutor@python.org >Subject: Re: [Tutor] don't understand iteration > >"Clayton Kirkwood&quo

Re: [Tutor] don't understand iteration

2014-11-10 Thread Alan Gauld
On 11/11/14 00:52, Clayton Kirkwood wrote: But group() - singular - returns a single group item which is always a string. You use group() to get the matching substring. You use groups to find all the substrings. I believe that is true only if you are receiving a single return value. If it is m

Re: [Tutor] don't understand iteration

2014-11-10 Thread Alan Gauld
On 11/11/14 00:28, Clayton Kirkwood wrote: This seems to be the only relevant words: 4.7.4. Unpacking Argument Lists ...when the arguments are already in a list or tuple but need to be unpacked > > for a function call If they are not available separately, write the function > call with

Re: [Tutor] don't understand iteration

2014-11-10 Thread Clayton Kirkwood
>-Original Message- >From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On >Behalf Of Alan Gauld >Sent: Monday, November 10, 2014 3:59 PM >To: tutor@python.org >Subject: Re: [Tutor] don't understand iteration > >On 10/11/14 23:08, Clayton Kirk

Re: [Tutor] don't understand iteration

2014-11-10 Thread Clayton Kirkwood
>-Original Message- >From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On >Behalf Of Ben Finney >Sent: Sunday, November 09, 2014 8:25 PM >To: tutor@python.org >Subject: Re: [Tutor] don't understand iteration > >"Clayton Kirkwood&quo

Re: [Tutor] don't understand iteration

2014-11-10 Thread Alan Gauld
On 10/11/14 23:08, Clayton Kirkwood wrote: I couldn't find a way to get the len of blah. What would you expect the answer to be? I would expect len(sizeof, whatever)(blah) to return the number of (in this case) matches, so 5. But remember that search is matching the pattern, not the groups

Re: [Tutor] don't understand iteration

2014-11-10 Thread Clayton Kirkwood
>-Original Message- >From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On >Behalf Of Alan Gauld >Sent: Monday, November 10, 2014 4:20 AM >To: tutor@python.org >Subject: Re: [Tutor] don't understand iteration > >On 10/11/14 00:34, Clayton Kirk

Re: [Tutor] don't understand iteration

2014-11-10 Thread Alan Gauld
On 10/11/14 00:34, Clayton Kirkwood wrote: if 'EST' in line or 'EDT' in line: # look for Eastern Time blah = re.search(r'<\w\w>(\w{3}\.)\s+(\d{2}),\s+(\d{2}).+([AP]M)\s+(E[SD]T)', line) (month, day, time, ap, offset) = blah.group(1,2,3,4,5) <_sre.SRE_Match object; span=(0, 28), match='

Re: [Tutor] don't understand iteration

2014-11-10 Thread Peter Otten
Clayton Kirkwood wrote: > > >>-Original Message- >>From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On >>Behalf Of Peter Otten >>Sent: Sunday, November 09, 2014 5:47 PM >>To: tutor@python.org >>Subject: Re: [Tutor] don't u

Re: [Tutor] don't understand iteration

2014-11-09 Thread Ben Finney
"Clayton Kirkwood" writes: > >-Original Message- > >From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On > >Behalf Of Dave Angel (Clayton, does your mail client not present messages written by their authors? The messages should not come to you “From:” the tutor list itself

Re: [Tutor] don't understand iteration

2014-11-09 Thread Clayton Kirkwood
>-Original Message- >From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On >Behalf Of Peter Otten >Sent: Sunday, November 09, 2014 5:47 PM >To: tutor@python.org >Subject: Re: [Tutor] don't understand iteration > >Clayton Kirkwood wrote: &

Re: [Tutor] don't understand iteration

2014-11-09 Thread Clayton Kirkwood
>-Original Message- >From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On >Behalf Of Dave Angel >Sent: Sunday, November 09, 2014 5:10 PM >To: tutor@python.org >Subject: Re: [Tutor] don't understand iteration > >You forgot to state your Py

Re: [Tutor] don't understand iteration

2014-11-09 Thread Peter Otten
Clayton Kirkwood wrote: > I have the following code: > blah = > re.search(r'<\w\w>(\w{3}\.)\s+(\d{2}),\s+(\d{2}).+([AP]M)\s+(E[SD]T)', > line) > (month, day, time, ap, offset) = blah.group(1,2,3,4,5) > This works fine, but in the (month... line, I have blah.group(1,2,3,4,5), >

Re: [Tutor] don't understand iteration

2014-11-09 Thread Dave Angel
You forgot to state your Python version. I'll assume 3.4 "Clayton Kirkwood" Wrote in message: > I have the following code: import urllib.request,re,stringmonths = > ['Jan.', 'Feb.', 'Mar.', 'Apr.', 'May.', 'Jun.', 'Jul.', 'Aug.', 'Sep.', > 'Oct.', 'Nov.', 'Dec.']from urllib.request import urlop