Custom placeholder like None in python

后端 未结 3 641
庸人自扰
庸人自扰 2020-12-19 04:33

I\'m using argspec in a function that takes another function or method as the argument, and returns a tuple like this:

((\"arg1\", obj1), (\"arg2\", obj2), .         


        
3条回答
  •  醉话见心
    2020-12-19 05:03

    There isn't any reason to not use such sentinel objects for such purposes. As an alternative to a class object, you could also create a singleton instance of a dynamically created type:

    NoDefault = type('NoDefault', (object,), {
        '__str__': lambda s: 'NoDefault', '__repr__': lambda s: 'NoDefault'})()
    

提交回复
热议问题