I have the following in a file named seta.py:
def print_name():
print "hello"
I am doing the following from the interpreter:
import seta
and then
seta.print_name
I would expect the output to be "hello" but it is as follows:
<function print_name at 0x7faffa1585f0>
What am i doing wrong?
To call a function you need to add ():
seta.print_name()
Otherwise it'll print the str/repr version of that function object.
Demo:
def func():
print "Hello, World!"
>>> func #Returns the repr version of function object
<function func at 0xb743cb54>
>>> repr(func)
'<function func at 0xb743cb54>'
>>> print func #Equivalent to `print str(func)`
<function func at 0xb743cb54>
>>> func() #Eureka!
Hello, World!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With