BackEnd/Python
python getattr, rsplit
Sh.TK
2018. 2. 21. 09:46
getattr
(object, name[, default])Return the value of the named attribute of object. name must be a string. If the string is the name of one of the object’s attributes, the result is the value of that attribute. For example, getattr(x,'foobar')
is equivalent to x.foobar
. If the named attribute does not exist, default is returned if provided, otherwise AttributeError
is raised.
rsplit
>>> '----a---b--c-'.rsplit('-') ['', '', '', '', 'a', '', '', 'b', '', 'c', ''] >>> '----a---b--c-'.rsplit('-', 1) ['----a---b--c', ''] >>> '----a---b--c-'.rsplit('-', 2) ['----a---b-', 'c', ''] >>> '----a---b--c-'.rsplit('-', 3) ['----a---b', '', 'c', ''] >>> '----a---b--c-'.rsplit('-', 4) ['----a--', 'b', '', 'c', ''] >>> '----a---b--c-'.rsplit('-', 5) ['----a-', '', 'b', '', 'c', ''] >>> '----a---b--c-'.rsplit('-', 6) ['----a', '', '', 'b', '', 'c', '']
참조: https://docs.python.org/3/library/functions.html#getattr