Reputation: 5434
I have a python/django project, with a django app called "testApp"
. under "testApp"
I have a python file: "hello.py"
. The file reads:
class Hello():
def sayHello():
print ("hello")
How can I activate the sayHello
function from python manage.py shell
importing "testApp"
doesn't help as calling "Hello.sayHello()"
gives out an undefined
error.
What am I doing wrong?
Upvotes: 0
Views: 538
Reputation: 599778
You need to import the actual name you want to use. Just importing testApp won't do anything; you would need to do from testApp.hello import Hello
.
Note also that since for some reason you have a class, sayHello
is an instance method and therefore needs to accept the self
parameter; also, you would need to instantiate the class before calling the method. However, Python is not Java, and there is absolutely no need for the Hello class to exist.
Upvotes: 1