title: Python: Can you dynamically get the amount of variables a function is going to return into?
body: <p>Part of a utility system my AcecoolLib package I'm writing by porting all / most of my logic to Python, and other various languages, on contains a simple, but greatly useful helper... a function named ENUM.</p>
  
  <p>It has many useful features, such as automatically creating maps of the enums, extended or reverse maps if you have the map assigned to more than just values, and a lot more. </p>
  
  <p>It can create maps for generating function names dynamically, it can create simple maps between enumeration and text or string identifiers for language, and much more.</p>
  
  <p>The function declaration is simple, too: </p>
  
  <pre><code>def ENUM( _count = None, *_maps ):
  </code></pre>
  
  <p>It has an extra helper... Here: <a href="https://www.dropbox.com/s/6gzi44i7dh58v61/dynamic_properties_accessorfuncs_and_more.py?dl=0" rel="nofollow noreferrer">https://www.dropbox.com/s/6gzi44i7dh58v61/dynamic_properties_accessorfuncs_and_more.py?dl=0</a></p>
  
  <p>The other one isn't used. <code>ENUM_MAP</code> is, but the other isn't.</p>
  
  <p>Anyway, before I start going into etc.. etc.. the question is:</p>
  
  <p>How can I count the return variables outside of the function... ie:</p>
  
  <pre><code>ENUM_EXAMPLE_A, ENUM_EXAMPLE_B, ENUM_EXAMPLE_C, ENUM_LIST_EXAMPLE, MAP_ENUM_EXAMPLE = ENUM( None, [ '#example_a', '#example_b', '#example_c' ] )
  </code></pre>
  
  <p>Where List is a simple list of <code>0 = 0, 1 = 1, 2 = 2</code>, or something. , then the map links so <code>[ 0 = '#example_a', 1 = '#example_b', etc.. ]</code>, then <code>[ '#example_a' = 0, etc.. ]</code> for reverse... or something along those lines.</p>
  
  <p>There are other advanced use cases, not sure if I have those features in the file above, but regardless... I'm trying to simply count the return vars... and get the names.</p>
  
  <p>I know it is likely possible, to read the line from which the call is executed... read the file, get the line, break it apart and do all of that... but I'm hoping something exists to do that without having to code it from scratch in the default Python system...</p>
  
  <p>in short: I'd like to get rid of the first argument of <code>ENUM( _count, *_maps )</code> so that only the optional <code>*_maps</code> is used. So if I call: <code>ENUM_A, ENUM_B, ENUM_C, LIST_ENUMS = ENUM( );</code> it'll detect 4 output returns, and get the name of them so I can see if the last contains certain text different from the style of the first... ie, if they want the list, etc.... If they add a map, then optional list, etc.. and I can just count back n _maps to find the list arg, or not...</p>
  
  <p>I know it probably isn't necessary, but I want it to be easy and dynamic so if I add a new enum to a giant list, I don't have to add the number ( although for those I use the maps which means I have to add an entry anyway )...</p>
  
  <p>Either way - I know in Lua, this is stupid easy to do with built-in functions.. I'm hoping Python has built in functions to easily grab the data too.</p>
  
  <p>Thanks!</p>