@staticmethod, backward compatibility?

Laszlo Zsolt Nagy gandalf at designaproduct.biz
Tue Sep 27 08:19:22 EDT 2005


Neal Becker wrote:

>How can I write code to take advantage of new decorator syntax, while
>allowing backward compatibility?
>
>I almost want a preprocessor.
>
>#if PYTHON_VERSION >= 2.4
>@staticmethod
>...
>
>
>Since python < 2.4 will just choke on @staticmethod, how can I do this?
>  
>
Decorators are there because

class MyClass:
    @staticmethod
    def my_method(arg1, arg2, ...):
        whatever

is nicer than

class MyClass:
    def my_method(arg1, arg2, ...):
        whatever
    my_method = staticmethod(my_method)

I'm affraid, if you need to be 2.3 compatible then you need to use the 
later form.

   Les





More information about the Python-list mailing list