1

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?

Finn Årup Nielsen
  • 6,130
  • 1
  • 33
  • 43
  • 1
    it is very old module and camera module is only experimental (see documentation) so don't expect too much. See source code and you see that `Camera` use some elements from `pygame.camera` which you didn't import so probably it can't find them (they are in different namespace) and this is why it get error. – furas Jan 18 '18 at 21:03
  • Unfortunately, I do not think many of us have used this part of the pygame library. Therefore, it is unlikely to get an answer on this. However, I agree with what furas mentioned. The module is very old and experimental which can cause a lot of problems and hassle. – Micheal O'Dwyer Jan 19 '18 at 19:08

0 Answers0