Can global variable be passed into Python function?
Roy Smith
roy at panix.com
Sun Mar 2 16:16:14 EST 2014
In article <87txbg48kd.fsf at elektro.pacujo.net>,
Marko Rauhamaa <marko at pacujo.net> wrote:
> Michael Torrie <torriem at gmail.com>:
>
> > I don't see why == wouldn't continue to work if os.POSIX_FADV_RANDOM
> > became an object of a different type.
>
> It probably would.
>
> If one were begging for trouble, one *could* define:
>
> class ABC:
> A = 1
> B = 1.0
> C = 1+0j
>
> Now:
>
> ABC.A == ABC.B
> ABC.B == ABC.C
> ABC.C == ABC.A
>
> but:
>
> ABC.A is not ABC.B
> ABC.B is not ABC.C
> ABC.C is not ABC.A
>
>
> Marko
On can do all sorts of bizarre things. If you wish to shoot yourself in
the foot, Python is happy to provide the gun.
class ABC(object):
_instance = None
def __new__(cls):
if cls._instance is None:
i = object.__new__(cls)
i.__class__ = ABC
cls._instance = i
return cls._instance
def __eq__(self, other):
return False
a = ABC()
b = ABC()
print a is b
print a == b
More information about the Python-list
mailing list