<HTML><HEAD></HEAD>
<BODY dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
<DIV>&nbsp;</DIV>
<DIV 
style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none">
<DIV style="FONT: 10pt tahoma">
<DIV>&nbsp;</DIV>
<DIV style="BACKGROUND: #f5f5f5">
<DIV style="font-color: black"><B>From:</B> <A title=waynejwerner@gmail.com 
href="mailto:waynejwerner@gmail.com">Wayne Werner</A> </DIV>
<DIV><B>Sent:</B> Thursday, November 17, 2011 8:30 PM</DIV>
<DIV><B>To:</B> <A title=o0MB0o@hotmail.se 
href="mailto:o0MB0o@hotmail.se">Mic</A> </DIV>
<DIV><B>Cc:</B> <A title=tutor@python.org 
href="mailto:tutor@python.org">tutor@python.org</A> </DIV>
<DIV><B>Subject:</B> Re: [Tutor] Clock in tkinter?</DIV></DIV></DIV>
<DIV></DIV>
<DIV 
style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none"></DIV>
<DIV class=gmail_quote>
<BLOCKQUOTE 
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" 
class=gmail_quote>
  <DIV dir=ltr>
  <DIV dir=ltr>
  <DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
  <DIV 
  style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none">
  <DIV class=gmail_quote>
  <DIV class=gmail_quote>
  <DIV>&nbsp;</DIV>
  <DIV>Say that I have a class and I want to make 100 objects. </DIV>
  <DIV>Then it could look like this:</DIV>
  <DIV>&lt;snip&gt; </DIV>
  <DIV><SPAN style="BACKGROUND-COLOR: transparent; DIRECTION: ltr">class 
  Chairs(object):</SPAN></DIV>
  <DIV><SPAN style="BACKGROUND-COLOR: transparent; DIRECTION: ltr">&lt;snip 
  code&gt;</SPAN><SPAN 
  style="BACKGROUND-COLOR: transparent">&nbsp;</SPAN></DIV></DIV></DIV></DIV></DIV></DIV></DIV></BLOCKQUOTE>
<BLOCKQUOTE 
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" 
class=gmail_quote>
  <DIV dir=ltr>
  <DIV dir=ltr>
  <DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
  <DIV 
  style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none">
  <DIV class=gmail_quote>
  <DIV class=gmail_quote>
  <DIV><SPAN style="BACKGROUND-COLOR: transparent; DIRECTION: ltr">&nbsp; 
  </SPAN></DIV>
  <DIV>#Create the objects</DIV>
  <DIV>chair1=Chairs("10","20")</DIV>
  <DIV>chair2=Chairs("10","20")</DIV>
  <DIV>chair3=Chairs("10","20")<SPAN 
  style="BACKGROUND-COLOR: transparent">&nbsp;</SPAN></DIV></DIV></DIV></DIV></DIV></DIV></DIV></BLOCKQUOTE>
<BLOCKQUOTE 
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" 
class=gmail_quote>
  <DIV dir=ltr>
  <DIV dir=ltr>
  <DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
  <DIV 
  style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none">
  <DIV class=gmail_quote>
  <DIV class=gmail_quote>
  <DIV>&nbsp;</DIV>
  <DIV>How do I shorten this? I have thought of using a for sling. I have looked 
  in my programming</DIV>
  <DIV>book and on the internet, but I don’t know how to make this shorter. The 
  arguements (“10”, “20”)</DIV>
  <DIV>should be the same for every object, which should make it easier than if 
  they were different each 
time?</DIV></DIV></DIV></DIV></DIV></DIV></DIV></BLOCKQUOTE>
<DIV>&nbsp;</DIV>
<DIV>If you ever write a line of code more than once, it's a good sign that you 
have what's called a code smell. This example is very smelly code ;)</DIV>
<DIV>&nbsp;</DIV>
<DIV>What you should do instead is have a collection of chairs:</DIV>
<DIV>&nbsp;</DIV>
<DIV>chairs = []</DIV>
<DIV>for _ in range(100): # the underscore `_` indicates that you don't care 
about the value</DIV>
<DIV>&nbsp;&nbsp;&nbsp; chairs.append(Chairs("10","20))</DIV>
<DIV>----------------------------------------------------------------------------------</DIV>
<DIV>&nbsp;</DIV>
<DIV>Yes, I got that right now. But now that you talked about shortening code, I 
have a general question.</DIV>
<DIV>What if I don’t write the same line of code more than once, but I write 
similiar lines more than once. Is that okay? <IMG 
style="BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP-STYLE: none; BORDER-LEFT-STYLE: none" 
class="wlEmoticon wlEmoticon-smile" alt=Ler 
src="cid:B397E3CA847946668FE771052495EC8E@MichaelxDator"></DIV>
<DIV>&nbsp;</DIV>
<DIV>For example:</DIV>
<DIV>value="green”</DIV>
<DIV>value_1=”green”</DIV>
<DIV>&nbsp;</DIV>
<DIV>click=-1</DIV>
<DIV>click1=-1</DIV>
<DIV>click2=-1</DIV>
<DIV>&nbsp;</DIV>
<DIV>I know that I can make this shorter, with a for sling for example, but the 
problem is that </DIV>
<DIV>I need to use these variables later in my program, and I don’t know how do 
to then, to be able</DIV>
<DIV>to use them later on, in a function for example. Do you have any general 
tips on how to make</DIV>
<DIV>your code shorter?</DIV>
<DIV>&nbsp;</DIV>
<DIV>I also hope I have learnt to post better now.</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks!</DIV>
<DIV>&nbsp;</DIV>
<DIV>Mic</DIV>
<DIV>&nbsp;</DIV></DIV></DIV></DIV></DIV></BODY></HTML>