help with calling a static method in a private class

Diez B. Roggisch deets at web.de
Tue Sep 14 16:38:50 CEST 2010


lallous <lallous at lgwm.org> writes:

> How can I keep the class private and have the following work:
>
> [code]
> class __internal_class(object):
>     @staticmethod
>     def meth1(s):
>         print "meth1:", s
>
>     @staticmethod
>     def meth2(s):
>         print "meth2:",
>         __internal_class.meth1(s)
>
> x = __internal_class()
>
> x.meth2('sdf')
> [/code]

By not using a double underscore. It is effectless on classes anyway
(they are not hidden because of that).

And additionally, but simply not using staticmethods at all. It's a
rather obscure feature of python - usually, classmethods are what is
considered a static method in other languages. And with that, even your
double underscores work:

class __internal_class(object):
    @classmethod
    def meth1(cls, s):
        print "meth1:", s

    @classmethod
    def meth2(cls, s):
        print "meth2:",
        cls.meth1(s)

x = __internal_class()

x.meth2('sdf')


Diez



More information about the Python-list mailing list