If you look at source of openpyxl, ```or` Make a note of some brilliant idioms that use the `` operator on strings.
In the self.title = title or self._default_title
part of the code below, if the argument title
of __init__
is None
or an empty string, the value of the class variable _default_title
" Sheet "
is set to self.title
as the default string.
child.py
class _WorkbookChild(object):
__title = ""
_id = None
_path = "{0}"
__parent = None
_default_title = "Sheet"
def __init__(self, parent=None, title=None):
self.__parent = parent
self.title = title or self._default_title
self.HeaderFooter = HeaderFooter()
Addendum) There was a detailed explanation in this article. http://qiita.com/keisuke-nakata/items/e0598b2c13807f102469
Recommended Posts