Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to use some math functions in a gDesklets applet, however, I can't import math in the script. I have googled but got nothing, except this similar post, yet unanswered.

I've tried to import at run time, but __import__ doesn't work:

name '__import__' is not defined                                                     
    2 #
>   3 math = __import__('math')

and neither could eval() work:

name 'eval' is not defined                                                           
    2 #
>   3 math = eval('__import__("math")')
share|improve this question
Uh.. Why vote to close? – Xiè Jìléi Jun 13 '11 at 3:04
up vote 0 down vote accepted

gDesklets is designed to be safe, so functions as import, eval, exec, etc., are disabled due to security reasons. To force enable these functions, you should change the source code:


  self.__environment["str"] = str
  self.__environment["sum"] = sum
+ self.__environment["__import__"] = __import__
+ self.__environment["eval"] = eval

(+) Added these two lines, functions __import__ and eval will then be available in the user scripts.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.