开发者

Why does my function call not print out what it's supposed to? [closed]

开发者 https://www.devze.com 2023-02-24 23:56 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhet开发者_如何学Corical andcannot be reasonably answered in its current form.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhet开发者_如何学Corical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
class A:
    def __init__(self, blocking, b = None):
        self.blocking = blocking

    def printerthing(self):
        print "hi this is a test"        

a = A(True)
a.printerthing
print("5")


You're not actually calling the function, you're just accessing a reference to it (and then doing nothing with it). You probably want:

a.printerthing()


try a.printerthing()?

Each method call has to have a ()


print in python3.x is different from print in python2.x

#!/usr/local/bin/python3

class A:
    def __init__(self, blocking, b = None):
        self.blocking = blocking

    def printerthing(self):
        print("hi this is a test")      

a = A(True)
a.printerthing
print("5")

it prints "5".

Andy

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号