<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Each type does contain its own parsing method.  It's just that, as it
stands, one method is being used to shunt off the data to the correct
parsing method.<br>
<br>
Matthew Dubins<br>
<br>
David Stanek wrote:
<blockquote
 cite="mid:de32cc030812251518nf38280amb2931d8289e7fb44@mail.gmail.com"
 type="cite">
  <pre wrap="">On Thu, Dec 25, 2008 at 1:22 PM, Matthew Dubins
<a class="moz-txt-link-rfc2396E" href="mailto:matt.dubins@sympatico.ca"><matt.dubins@sympatico.ca></a> wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Hello all,

I have made a python script to upload contact information from an excel
worksheet to an online database.  One part of the program that really
tripped me up was when I wanted to call specific class methods that I had
made to deal with specific types of contact information (Parent's name,
Child's name, Phone #, etc).  My first thought was to make it easy using the
exec statement.
The code (a method within a class) looked like this:
----------
def parse(self, data, data_type)
  exec "self.__parse_%s(data)" % data_type
----------
The data_type variable contains strings that exactly match the spellings of
the 2nd word in the titles of the class methods that I wanted to call for
each data_type inputted into the parse function.  For some reason, *it
didn't work*.  Alternately, I found the ugly code shown below to be
functional.  As you can see, for each data_type, I call the corresponding
class method that I've specified.  Please help me to transform my ugly
functional code into concise functional code. :)

Thanks,
Matthew
----------
  def parse(self, data, data_type):
      if data_type == 'nocall':
          self.__parse_nocall(data)
      elif data_type == 'DOB':
          self.__parse_DOB(data)
      elif data_type == 'gender':
          self.__parse_gender(data)
      elif data_type == 'Prematurity':
          self.__parse_Prematurity(data)
      elif data_type == 'email':
          self.__parse_email(data)
      elif data_type == 'languages':
          self.__parse_languages(data)
      elif data_type == 'phone':
          self.__parse_phone(data)
      elif data_type == 'cname':
          self.__parse_cname(data)
      elif data_type == 'pname':
          self.__parse_pname(data)
      elif data_type == 'address':
          self.__parse_address(data)
      elif data_type == 'duedate':
          self.__parse_dudedate(data)

    </pre>
  </blockquote>
  <pre wrap=""><!---->
I would look for a way to reorganize your code so that each type
contains its own parse method.


  </pre>
</blockquote>
<br>
</body>
</html>