[Tutor] For Loop Question

Tom Tucker tktucker at gmail.com
Mon Dec 24 02:03:44 CET 2012


Python Gurus,
I got a question for ya.  Below I have three instance variables (self.A,
self.B, etc).  How can I use the below
for loop for A, B, C to also call those instance variables?

Example
###############
<some code>
.....
.....
 self.A          = 1
 self.B    = 2
 self.C    = 3

myDict = {'A': 1, 'B': 2, 'C': 1}
for x in [A, B, C]:

  if myDict[x] == (self.%s % (x)): # Invalid if statement.. ;-)
print "Yep, we have a match!"
  else:
print "Sorry..No match!"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121223/c6244aed/attachment-0001.html>


More information about the Tutor mailing list