errors getting python up-and-running

lkcl luke.leighton at gmail.com
Sat Nov 27 07:53:10 CET 2010




Adam Lackorzynski wrote:
> 
>> is that... basically it? then include the file e.g. site.py as a module?
>> there must be a "good" way to do this, surely.
> 
> Well, never tried it. When you add the site.py file in modules.list it
> will appear as rom/site.py in python. Can you load it?
> 
> 

well, luckily i'm a python expert :)

*adds site.py to modules.list*
*builds a qemu iso*
*fires up qemu*
*watches python go "splat" on importing site.py*
*goes "hmmmm"...*

>>> import site
ImportError: module site not found
>>> import sys
>>> dir(sys)
{usual stuff}
>>> print sys.path
['', '']

ah ha!  clue!

>>> sys.path.append('rom')
>>> import sys
ImportError: module os not found

so, yaay!  yes it's possible to add python modules directly to modules.list,
and as long as sys.path is modified to look in 'rom' as one of the
subdirectories (that'll need hard-coding into the python source code) it
should all be hunky-dory.

now, here's the thing that would help enormously.  python's import mechanism
doesn't _just_ have to be a filesystem.  you _can_ create overrides of
__import__.  i've done this before to actually override to load modules from
a SQL database! (don't ask...) - of course that first "bootstrap" module has
to be on a filesystem, or otherwise you have to write it in c and hard-code
its existence into the python binary, which i believe is completely
unnecessary in this case.

one example to follow is ".egg" files.  .egg files are zip'd archives which
can be inserted into the sys.path and python will then look for the modules
*inside* that sys.path.

basically what i'm saying is that site.py, os.py and pretty much everything
under-the-sun in the standard python libs could be dumped into a zip'd
archive - a single file - out of which the python binary could extract
whatever it requires.  the only down-side of that is that a) it's a single
file b) looking for a particular module and then uncompressing it is going
to involve CPU cycles.

but it would be bloody sight easier than having to add everything to
modules.list.

there _must_ be a convenient way to add a ROM-based filesystem to L4,
surely.  or any kind of filesystem.

l.

-- 
View this message in context: http://old.nabble.com/errors-getting-python-up-and-running-tp30308895p30317089.html
Sent from the L4 mailing list archive at Nabble.com.





More information about the l4-hackers mailing list