0

I have a folder called pack1, and two python files called Task1 and HelloW. For some reason I'm getting this error:

ImportError: cannot import name 'HelloW'

Here is the code:

# file HelloW
class HelloW:
    name = "John Doe"

    def print_hello(self):
        print("Hello, %s" % self.name)


#file Task1
from pack1 import HelloW

hw = HelloW()
hw.print_hello()
Xerath
  • 919
  • 5
  • 13
  • 23

2 Answers2

1

I suggest renaming HelloW.py to hellow.py (according to http://legacy.python.org/dev/peps/pep-0008/#package-and-module-names modules and packages should have all-lowercase names).

Then try updating your import statement to import the HelloW class from hellow module:

from hellow import HelloW
leporo
  • 604
  • 7
  • 7
  • Nvm, I found answer here http://stackoverflow.com/questions/21236824/unresolved-reference-issue-in-pycharm – Xerath Apr 12 '14 at 13:35
0

Try to create an empty file called __init__.py in your pack1 directory.

RdB
  • 1,198
  • 1
  • 15
  • 23
  • Doesn't fix the problem. Also in addition to this, I'm using an IDE PyCharm, it highlights my line hw = HelloW() with a yellow color, with a message when i hover over 'HelloW' is not callable – Xerath Apr 12 '14 at 12:59