type lookuperror

meInvent bbird jobmattcon at gmail.com
Thu Aug 18 03:44:10 EDT 2016


if i use 

result = ""
before try
and return result at the end

as return of function can be any type

there will be type mismatch 

how to return the result of func ?

On Thursday, August 18, 2016 at 3:18:31 PM UTC+8, Chris Angelico wrote:
> On Thu, Aug 18, 2016 at 5:14 PM, Peter Otten <__peter__ at web.de> wrote:
> > meInvent bbird wrote:
> >
> >> when try keystone_client.tenants.get
> >> got error,
> >>
> >> isn't this method for all kinds of function?
> >>
> >>>>> m = "4c9a0da00b904422a23341e35be7f8d7"
> >>>>> ten = checkexception(keystone_client.tenants.get,
> >>>>> tenant_id=checkexception(m.encode,encoding='ascii',errors='ignore'))
> >> Unexpected error: <class 'keystoneclient.apiclient.exceptions.NotFound'>
> >> None
> >
> > That's because your and Chris' version of checkexception() have no explicit
> > return statement and thus always return None. There doesn't seeem to be a
> > tenant_id=None...
> 
> Hmm. Yes, that's another bug I should have fixed as I was rewriting.
> "return result" at the end.
> 
> ChrisA




More information about the Python-list mailing list