Skip to main content

Python text operations module

Project description

When you access an object with chained attributes

info = obj.a.b.c.d or 'Unknown'

Usually, it will failed when one intermediate attribute return ‘None‘

if obj.a returns None
obj.a.b.c.d will fail with that exception :
AttributeError: 'NoneType' object has no attribute 'xxx'

To avoid that, instead of returning a ‘None‘ value, one should return ‘NoAttr‘, by this way, even next chained attribute will return ‘NoAttr‘

if obj.a returns NoAttr
obj.a.b.c.d will not fail and will return NoAttr

‘NoAttr‘ can be seen as False, ‘’, [], {} depending on the context, so

if obj.a returns NoAttr
obj.a.b.c.d or 'Unknown' will return 'Unknown'

News

0.0.1 (2015-07-27)

First version

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

noattr-0.0.1.tar.gz (2.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page