在python中从类中的函数返回True | False

在python中从类中的函数返回True | False,python,class,function,boolean,return,Python,Class,Function,Boolean,Return,我无法从函数中获取返回值True | False。 我做错了什么 剧本大致上是这样的 class getLogs: IAM=getpass.getuser() SRC_LOG_DIR='/server/log/session/' DST_LOG_DIR="/home/${IAM}/LOGS/" def __init__(self): parser = argparse.ArgumentParser() parser.add_a

我无法从函数中获取返回值True | False。 我做错了什么

剧本大致上是这样的

class getLogs:

    IAM=getpass.getuser()
    SRC_LOG_DIR='/server/log/session/'
    DST_LOG_DIR="/home/${IAM}/LOGS/"

    def __init__(self):

        parser = argparse.ArgumentParser()
        parser.add_argument("-S","--sessId", type=int, help="The SessionId of the logs to retreive for.")
        args = parser.parse_args()



        if not args.sessId:
            args.sessId = 'ns'
            os.system('clear')
            print ('\tNo sessid was set.')
            print ('\tTip: you can see what options you have by running "{} -h"'.format(__file__))            

        self.getSessID(args.sessId)

        if self.getSessID:
            print('\tI will get the logfiles for session ID "{}".'.format(self.sessId))            
            #Do something else

    def getSessID(self, sessId):

        if sessId == 'ns':
            menu='on'        
            while menu=='on':

                sys.stdout.write("\tPlease give me the sessionid of the logging :")
                sessId = raw_input()
                test = re.match("^[0-9]{5,7}$",sessId)

                if test:
                    menu='off'


                if not test:
                    print('\tError:\n\tSessionID should contain only numbers')
                    print('\tor sessID was not defined.')
                    print('\tor sessID length must be 5 to 7 characters')

        self.sessId = sessId
        return True
我从这个
print self.getsessiond
和构造函数中的
if self.getsessiond
得到的是这个

我肯定我做错了什么,我不知道如何从函数的返回中获取值。
有人能帮我吗?

您没有对该方法进行任何操作,然后测试该方法是否存在:

self.getSessID(args.sessId)

if self.getSessID:
    print('\tI will get the logfiles for session ID "{}".'.format(self.sessId))            
您需要存储结果并测试:


也可能是您想要测试
self.sessiond
,这是您在
self.getsessiond()
方法中设置的。

修复代码中的缩进。您必须调用该方法/函数……您正在测试
self.getsessiond
,而不调用它;它总是
True
,因为那里有一个函数对象,而不是一个结果。或者更准确地说,当您调用它时,您需要保存返回值;您正在检查名称
self.getsessiond
是否未绑定到假值。我不是在这里调用该函数吗<代码>self.getsessiond(args.sessiond)哦,伙计们,非常感谢你们!不,我终于可以做一些工作了!
session_id = self.getSessID(args.sessId)

if session_id:
    print('\tI will get the logfiles for session ID "{}".'.format(session_id))