calling class methods without instance

Josh Close narshe at gmail.com
Wed Sep 22 22:38:56 CEST 2004


Is there a way to call a class method without an instance of that class?

class myClass:
  def printSomething(message):
    print message

myClass.print()

That's basically what I want to do. Is there a way to do that without
having to do

c = myClass()
c.print()

I've tried using

class myClass:
  def printSomething(message):
    print message
  printSomething = staticmethod(printSomething)

but that didn't seem to work either. I'm probably just missing
something really simple here.

-Josh



More information about the Python-list mailing list