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

Re: [pygame] Checking For Pygame



On 10/14/06, Greg Ewing <greg.ewing@xxxxxxxxxxxxxxxx> wrote:

So just go ahead and import it wherever you need

If Kris' function is called lots of times, issuing an "import pygame" in it will consume unnecessary cpu-power. This is because as soon as soon as the function exits, the pygame-module will be unloaded. Imported modules within functions will not be visible outside it, because of the scope rules in Python.

dir()
['__builtins__', '__doc__', '__name__']
def foo():
...   import math
...   pass
...
foo()
dir()
['__builtins__', '__doc__', '__name__', 'foo']
def bar():
...   import string
...   print dir()
...
bar()
['string']
dir()
['__builtins__', '__doc__', '__name__', 'bar', 'foo']
import math
dir()
['__builtins__', '__doc__', '__name__', 'bar', 'foo', 'math']



--
- Rikard.