Hannibaal
Hannibaal

Reputation: 97

static method in Python not working

I'm learning by my self Python and I have a mind blowing issue, because I don't understand why is not working. I'm using PyDev and I've download version 2 of Python. I have this code:

class Utils:

    @staticmethod
    def hello():
        print "Hi! I'm the Utils class"

Utils.hello() #Hi! I'm the Utils class

and everything is working fine at this point. But if I import the Utils class and call the static method from another module...

import Utils

Utils.hello()

I get this error:

Traceback (most recent call last):
  File "C:\Users\migugonz\Desktop\Docs\Per Folder\WorkSpacePy\Rosalind\src\bioinformatics\stronghold\Pruebas.py", line 40, in <module>
    Utils.hello()
AttributeError: 'module' object has no attribute 'hello'

I thing it can't be a big deal, but I've been searching a solution and as long I know this shlould be work.

Upvotes: 7

Views: 8493

Answers (1)

YOU
YOU

Reputation: 123791

I believe you need to do Utils.Utils.hello()

or import like from Utils import Utils

Upvotes: 16

Related Questions