Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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                                                     
/usr/lib/gdesklets/Displays/Clock/clock.display                                      
    1
    2 #
>   3 math = __import__('math')

and neither could eval() work:

name 'eval' is not defined                                                           
/usr/lib/gdesklets/Displays/Clock/clock.display                                      
    1
    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
add comment

1 Answer 1

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:

/usr/lib/gdesklets/scripting/Script.py:

  ...
  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
add comment

Your Answer

 
discard

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.