You are here: Home / Documentation / How To's / How to allow import of modules for Script (Python) objects

How to allow import of modules for Script (Python) objects

by nguyen — published Sep 04, 2009 03:45 PM, last modified Aug 16, 2016 10:50 AM
Useful if you want to use a Script (Python) instead of an External Method. Not safe to abuse this!

If you want to use most Python modules within a script, you normally have to put the script within an External Method, which requires that you create a file on the file system.  This is for safety reasons, that restricted Python (what runs any ZMI TTW "Script (Python)" objects) prevents you from importing arbitrary modules.

If you want to allow importing of specific modules into a Script (Python), here's how.  In this example we want to allow importing of the module "marshal".

  • In your Zope's products or Products dir create a new dir, call it "allow_module"
  • Inside the new dir, create a file "" containing
    from AccessControl import allow_module
  • Restart your Zope or your ZEO client(s)

Be careful which modules you allow!  Some may be very CPU intensive.