title: Python: Convert string into function name; getattr or equal?
body: <p>I am editing PROSS.py to work with .cif files for protein structures. Inside the existing PROSS.py, there is the following functions (I believe that's the correct name if it's not associated with any class?), just existing within the .py file:</p>
  
  <pre><code>...
  def unpack_pdb_line(line, ATOF=_atof, ATOI=_atoi, STRIP=string.strip):
  ...
  ...
  def read_pdb(f, as_protein=0, as_rna=0, as_dna=0, all_models=0,
      unpack=unpack_pdb_line, atom_build=atom_build):
  </code></pre>
  
  <p>I am adding an optons parser for command line arguments, and one of the options is to specify an alternate method to use besides unpack_pdb_line. So the pertinent part of the options parser is:</p>
  
  <pre><code>...
  parser.add_option("--un", dest="unpack_method", default="unpack_pdb_line", type="string", help="Unpack method to use. Default is unpack_pdb_line.")
  ...
  unpack=options.unpack_method
  </code></pre>
  
  <p>However, options.unpack_method is a string and I need to use the function with the same name as the string inside options.unpack_method. How do I use getattr etc to convert the string into the actual function name?</p>
  
  <p>Thanks,</p>
  
  <p>Paul</p>