Consider this line in the pygame loop:
pygame.display.set_mode().fill((0, 200, 255))
From: http://openbookproject.net/thinkcs/python/english3e/pygame.html
I. How are you supposed to know there even is a fill function nested in set_mode? I searched in the pygame documentation and there is no information on fill in the set_mode section.
II. set_mode() is a function of the display module of the pygame package. How can I call a function nested in another function?
How could I call print"hi" with this function(tried it but get an AttributeError):
def f():
def g():
print "hi"
The pygame.display.set_mode() returns a Surface object.
From the documentation:
So you are calling the method
.fill()on the surface object, not on the functionset_mode().You can find the methods available on surface objects in the surface documentation of pygame.
You cannot call a nested function in that way.
To get your desired result in your print example, you can use classes in the following way:
Resulting in:
This is a simplified example to show how the
display.set_mode().fill()works:Edit:
You can use nested functions, but it works slightly different from how you would do it with objects and modules:
Resulting in: