On a Linux computer with pygame 1.9.3 I am puzzled by the implementation of the initialization of the pygame camera. The code below demonstrates the surprising behavior: In the first call to Camera (pygame.camera.Camera
) the camera will be initialized, while the second call (Camera
) raises a NotImplementedError
.
>>> from pygame.camera import Camera, init as camera_init
>>> import pygame.camera
>>>
>>> camera_init()
>>> camera = pygame.camera.Camera("/dev/video0")
>>> camera = Camera("/dev/video0")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/pygame/camera.py", line 102, in __init__
raise NotImplementedError()
NotImplementedError
It must arise from the Camera
class being declared a global variable and redefined to point to the actual implementation in the camera.py
file. The first call uses the redefined variable while the second uses the original Camera
class.
It strikes me as an surprising implementation that may take some time to debug. Could this not be implemented under a factory pattern?