import from a database / a string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Harald Massa

    import from a database / a string

    Hello,

    since some time I try to find a more elegant solution:

    modules of an application are stored in a database, and depending on the
    logged on user different modules are integrated into the application.

    actually I store the source-code in big text fields, get it and integrate
    it via compile and execute.

    c=getCodeFromDa tabase(identifi er)
    obj=compile(c,' <ausdb>','exec' )
    exec obj in globals()

    (with some try: and excepts:)

    there could be some improvements by not executing in globals() ... but


    I assume, there should be a better solution with the new import-
    flexibility.

    So I like to compile my module to an .pyo, store this .pyo into the
    database, and do something like

    import modulefromdatab ase as specialname


    I just can't figure out how, some materials about the new importhooks did
    not help, neither did googling... can somebody push me in the correct
    direction?


    Harald
Working...