티스토리 뷰

BackEnd/Python

python getattr, rsplit

Sh.TK 2018. 2. 21. 09:46
getattr(objectname[default])

Return the value of the named attribute of objectname 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

댓글
공지사항
최근에 올라온 글
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함