RM1970 RM1970 - 11 months ago 40
Python Question

can't call an existing function from python shell

I have a python/django project, with a django app called

. under
I have a python file:
. The file reads:

class Hello():
def sayHello():
print ("hello")

How can I activate the
function from
python manage.py shell

doesn't help as calling
gives out an

What am I doing wrong?


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.