How to statically bind modules written in Python

Travis Nixon tnixon at avalanchesoftware.com
Thu Oct 19 12:13:30 EDT 2000


Yeah, I think I had pretty much come to the conclusion that doing this would require making changes to how Python imports things, and once I got there, I could pretty much feel free to do whatever I want. :)  Embedding it in a C file as a string is not something I had considered, though, and sounds like a good way to keep everything together in one place (ie, in my statically bound python.lib)

Thanks for the input everybody. :)
  ----- Original Message ----- 
  From: jay.krell at cornell.edu 
  To: Travis Nixon ; python-list at python.org 
  Sent: Thursday, October 19, 2000 12:53 AM
  Subject: Re: How to statically bind modules written in Python


  Solution 3b: put the files' contents in strings. Modify wherever it is in Python that resolves "import" to know about your built in ones. It should not be hard.
   
  You could even write a few lines of Python to turn the .py file
  -- foo.py --
  abc
  123
  this is supposed to be Python code
  -- foo.py --
   
  into a C source file
   
  const char foo_py[] =
  "abc\n"
  "124\n" 
  "this is supposed to be Python code\n"
  ;

  Then you'll need a table somewhere
  const static struct PyMap { const char* name, const char* contents; } pyMap[] = { { "foo", foo_py } };
   
  you could even put the string right in the array, depending on how/if you automate the build.
   
  This is a pretty standard trick. You can embed binary files in source similarly. Even write out .dlls at runtime for like a runtime install. You don't need "resources" for any of this, and the data approach works better if you want to put anything in static .libs..
   
   - Jay
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20001019/7df5c7dd/attachment.html>


More information about the Python-list mailing list