[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Checking For Pygame



The somewhat simple solution I would think would be:
>>> if 'pygame' in dir()
I suppose this would assume that the proper pygame module is being imported, and that somewhere it doesn't say
>>> pygame = None
or something of that sort.  But if you trust/know 100% of the code that pygame is only defined with the import (of the proper module), then is there anything wrong with that way of checking?


On 10/14/06, Farai Aschwanden <fash@xxxxxxxxxx> wrote:
I never tested it but you can try this:

try:
   calling simple pygame function

except:
   # ImportError
   import pygame

And Im also not sure about this (prove me wrong ;) ): If you create
later on a py2exe or py2app it will be remove all the same modules to
one, so the same module will not be loaded more than once. I think I
read that once on a page. There are also module variables set you can
check if a module is loaded.


Am 14.10.2006 um 02:19 schrieb Kris Schnee:

> How can I find out whether Pygame is currently loaded? I'd like to
> use a function that requires Pygame to draw something, without
> loading the module in the program unless that function runs?
>
> Right now the function itself says "import pygame," but I'd like to
> account for the possibility that pygame will already be loaded when
> the file it's a part of is incorporated into a bigger project.
>
> Kris