Search code examples
pythoncoding-styleimportpyjamas

Pyjamas import statements


I'm starting to use Pyjamas and I'm running into some annoyances. I have to import a lot of stuff to make a script work well. For example, to make a button I need to first

from pyjamas.ui.Button import Button

and then I can use Button. Note that

import pyjamas.ui.Button

and then using Button.Button doesn't work (results in errors when you build to JavaScript, at least in 0.7pre1). Does anyone have a better example of a good way to do the import statements in Pyjamas than what the Pyjamas folks have on their site? Doing things their way is possible, but ugly and overly complicated from my perspective, especially when you want to use a dozen or more ui components.


Solution

  • If you want to be able to say Button.Button, then instead of

    import pyjamas.ui.Button
    

    you should write

    from pyjamas.ui import Button
    

    Otherwise you need to use pyjamas.ui.Button.Button. What ends up in your namespace is what you have after the import keyword.