title: How to make normal class from a factory in another module?
body: <p>[The day after] I figured it out- I didn't even know what question to ask.</p>
  
  <p>The solution is to extend the golbals() dictionary of the user module with the dictionary of structure classes I build while parsing the.c and 'h files.
  <code>globals().update(Structures.struct_dict)</code> is all it took to be able to instantiate my derived classes without having to jump through hoops.</p>
  
  <p>Thanks for the help (whether in comments here or by email), it did get me on the rails.</p>
  
  <p>Original question is below</p>
  
  <hr>
  
  <p>I am new to Python (and to stack overflow) and I am struggling a little with the scoping of objects.</p>
  
  <p>I am making an automated test framework that connects over USB to some machine, then issues commands, reads variables and data streamed by the machine and reacts to it.</p>
  
  <p>In order to facilitate the scripting I wrote a C/C++ preprocessor that slurps all the C source for the machine's code and the resulting map file so that the testers can use the #defines and #enums as well as query variables by their names in C.</p>
  
  <p>All this works fine but to be very useful I need to be able to generate a class for each type of structure I find defined in the source so that when my test code reads the raw data and returns a bytearray the user could do</p>
  
  <pre><code>myStruct = SomeStructClass(received_bytearray)
  process(myStruct.structure_member_name_from_C_source)
  </code></pre>
  
  <p>I got the parsing done and I can generate the classes OK but I end up with a dictionary of <code>{name:class}</code> that is quite unwieldy.</p>
  
  <p>I end up importing the dictionary and requiring the user who writes the test script proper to do weird stuff such as:</p>
  
  <pre><code>from Structures import struct_dict
  C_struct_name = struct_dict["C_struct_name"]
  myStruct = C_struct_name(initial_data)
  </code></pre>
  
  <p>So here is my question:</p>
  
  <p>How can I make it that a simple import from my Structures module defines the new structures I created in Structures in the global scope of the importing script?</p>
  
  <p>In other words, can I automate the second line of my previous code snippet?</p>
  
  <p>In advance thanks a ton!</p>