[Tutor] don't understand iteration

Dave Angel davea at davea.name
Mon Nov 10 02:10:18 CET 2014


You forgot to state your Python version. I'll assume 3.4

"Clayton Kirkwood" <crk at godblessthe.us> Wrote in message:
> <!--
> /* Font Definitions */
> @font-face
> 	{font-family:"Cambria Math";
> 	panose-1:2 4 5 3 5 4 6 3 2 4;}
> @font-face
> 	{font-family:Calibri;
> 	panose-1:2 15 5 2 2 2 4 3 2 4;}
> /* Style Definitions */
> p.MsoNormal, li.MsoNormal, div.MsoNormal
> 	{margin:0in;
> 	margin-bottom:.0001pt;
> 	font-size:11.0pt;
> 	font-family:"Calibri","sans-serif";}
> a:link, span.MsoHyperlink
> 	{mso-style-priority:99;
> 	color:blue;
> 	text-decoration:underline;}
> a:visited, span.MsoHyperlinkFollowed
> 	{mso-style-priority:99;
> 	color:purple;
> 	text-decoration:underline;}
> span.EmailStyle17
> 	{mso-style-type:personal-compose;
> 	font-family:"Calibri","sans-serif";
> 	color:windowtext;}
> .MsoChpDefault
> 	{mso-style-type:export-only;}
> @page WordSection1
> 	{size:8.5in 11.0in;
> 	margin:1.0in 1.0in 1.0in 1.0in;}
> div.WordSection1
> 	{page:WordSection1;}
> -->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 urlopenfor line in urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl'):    line = line.decode('utf-8')  # Decoding the binary data to text.    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) 

You apparently know you want exactly 5 items, and you want them in
 order, so you need 5 arguments,  in order. If you don't like what
 you have, you can pass a list, if you precede it with an
 asterisk. 

(month, day, time, ap, offset) = blah.group( *list (range (1, 6)))

Should do it.


-- 
DaveA



More information about the Tutor mailing list