Quote:
Originally Posted by capink
Can be useful for also defining convenience methods in the future, that simplifies repetitive tasks, and can be called using the ctx.convenience_method()
|
True. For example I frequently write the same code to deal with metadata that is None vs a non-existent attribute. For example, mi.get('#custcol', 'foo') will never return 'foo' if '#custcol' exists. If you want a default for an empty column then you must do something like
Code:
'foo' if mi.get('#custcol') is None else mi.get('#custcol')
One way is a helper method:
Code:
def get_default_if_none(book, field, default):
v = book.get(field, None)
return default if v is None else v