0

関数から戻り値 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.getSessIDif self.getSessIDコンストラクター関数から得られるのはこれです<bound method getLogs.getSessID of <__main__.getLogs instance at 0x7f5aa28e1518>>

関数の戻り値から値を取得する方法がわかりません。誰か助けてくれませんか?

4

1 に答える 1

1

メソッドで何もしていないので、メソッドが存在するかどうかをテストします。

self.getSessID(args.sessId)

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

結果を保存し、次のことをテストする必要があります。

session_id = self.getSessID(args.sessId)

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

self.sessIdメソッドで設定したをテストしたい場合もありますself.getSessID()

于 2013-06-05T20:10:35.387 に答える