Python string formatting - limit string length, but trim string beggining -
Python string formatting - limit string length, but trim string beggining -
i'm using python standard logging module custom formatter limit length of fields. uses standard %
python operator.
i can apply limit percent-formatted string (this limits length 10 chars):
>>> "%.10s" % "lorem ipsum" 'lorem ipsu'
is possible trim beginning, output 'orem ipsum'
(without manipulating right-side argument)?
python's % formatting comes c's printf.
note .
indicates precision float. works on string mere side effect, , unfortunately, there no provision in string formatting specification accommodate stripping string left fixed max width.
therefore if must strip string fixed width end, recommend piece negative index. operation robust, , won't fail if string less 10 chars.
>>> up_to_last_10_slice = slice(-10, none) >>> 'lorem ipsum'[up_to_last_10_slice] 'orem ipsum' >>> 'ipsum'[up_to_last_10_slice] 'ipsum'
python string
Comments
Post a Comment