It looks like there is a function as well as a class associated with the name
Is it possible for a class and a function that share a common name?
My guess is that at this moment cv2.VideoCapture represents a class and a function as well.
<built-in function VideoCapture>
>>>camera = cv2.VideoCapture(0)
All depends on what you call “name”…
>>> class Foo(object):
>>> _Foo = Foo
>>> def Foo():
... return _Foo()
>>> f = Foo()
<function Foo at 0x7f74a5fec8c0>
As you can see, you here have a function exposed as
Foo and having it’s
__name__ == “Foo”, and a class exposed as
_Foo but having
__name__ == “Foo” too.
To answer your question: you cannot have the same name (=> variable) bound to more than one object at a given time in a given namespace. But you can have has many objects has you want having the same value for a
I have not checked the
OpenCV source code in order to check out what or why is going on in this specific case, but in theory this can be possible if your function returns an instance of a class with the same name.
consider the file cv2.py with the following content
>>> import cv2
<function VideoCapture at 0x7f70d36069b0>
>>> camera = cv2.VideoCapture(0)
Yes, they can have same name, if they are situated in different scopes.
>>> import one
<function A at 0x7f1b9f132b70>
>>> import two