How to replace custom tabs with spaces in a string, depend on the size of the tab?

前端 未结 12 2077
無奈伤痛
無奈伤痛 2021-01-17 15:13

I\'m trying to write a python function not using any modules that will take a string that has tabs and replace the tabs with spaces appropriate for an inputted tabstop size.

12条回答
  •  抹茶落季
    2021-01-17 15:25

    For a tab length of 5:

    >>> s = "123\t123"
    >>> print ''.join('%-5s' % item for item in s.split('\t'))
    123  123  
    >>> 
    

提交回复
热议问题