title: How do I get the name from a named tuple in python?
body: <p>I create a named tuple like this:</p>
  
  <pre><code>from collections import namedtuple
  spam = namedtuple('eggs', 'x, y, z')
  ham = spam(1,2,3)
  </code></pre>
  
  <p>Then I can access elements of ham with e.g.</p>
  
  <pre><code>&gt;&gt;&gt; ham.x
  1
  &gt;&gt;&gt; ham.z
  3
  </code></pre>
  
  <p>In the interpreter,</p>
  
  <pre><code>&gt;&gt;&gt; ham
  eggs(x=1, y=2, z=3)
  </code></pre>
  
  <p>But what if I just want to get 'eggs'? The only way I've been able to think of is</p>
  
  <pre><code>&gt;&gt;&gt; ham.__repr__.split('(')[0]
  'eggs'
  </code></pre>
  
  <p>but this seems a bit messy. Is there a cleaner way of doing it?</p>
  
  <p>Why do named tuples have this 'eggs' aspect to them if it isn't possible to access it without resorting to a private method?</p>