Can global variable be passed into Python function?

Marko Rauhamaa marko at pacujo.net
Sun Mar 2 05:37:13 EST 2014


Chris Angelico <rosuav at gmail.com>:

> And there's another thing you can do to test.
>
>>>> import os
>>>> type(os.POSIX_FADV_RANDOM)
> <class 'int'>

Is that what you do in your programs?

> So use ==. If it's later changed and you have to instead use 'is', you
> can change your code.

Quite a robust API, huh?

Anyway, you recognize that the API definer is within their rights to
require 'is' semantics for the constants. IOW, the application must use
the given constant objects and nothing that happens to be == to them.

Consequently, the implementer is within their rights to define:

   def __eq__():
       return True


Marko



More information about the Python-list mailing list