How to call a method returning a value from a main function

Paul Moore p.f.moore at gmail.com
Wed Sep 28 04:42:15 EDT 2016


On Wednesday, 28 September 2016 07:47:38 UTC+1, prasanth kotagiri  wrote:
> def GenAccessToken(mackey,authid,configid,tokenexp,*perm):
>     args=JWTParms()
>     args.configurationId=configid
>     args.authzSystemMacKey=mackey
>     args.authzSystemId=authid
>     args.tokenExpiryInSeconds=tokenexp
>     args.permissions=perm
>     tokenGen=TokenGenerator(args)
>     tok=tokenGen.generate()
>     return tok
> 
> if __name__ == '__main__':
>       GenAccessToken("This_is_a_Test_QED_MAC_Key_Which_Needs_to_be_at_Least_32_Bytes_Long", "default", "default", 60000,
>            "g,m,a,s,c,p,d")
> 
> when i am calling the above method it is not returning any value but when i use print it is printing the value. Is there any wrong in returning the value from above method. Please help me ASAP

GenAccessToken is returning a value (from "return tok") but you're not doing anything with that value in your "if name == '__main__'" section. You need to assign the return value to a variable, or print it, or whatever you want to do with it. Otherwise Python will assume you weren't interested in the return value and simply throw it away.

Try something like

    tok = GenAccessToken("This_is_a_Test_QED_MAC_Key_Which_Needs_to_be_at_Least_32_Bytes_Long", "default", "default", 60000,
                "g,m,a,s,c,p,d")
    print(tok)

Paul



More information about the Python-list mailing list