Grab a line's whitespace/indention with Python

前端 未结 6 1744
轮回少年
轮回少年 2020-12-06 10:48

Basically, if I have a line of text which starts with indention, what\'s the best way to grab that indention and put it into a variable in Python? For example, if the line i

6条回答
  •  情深已故
    2020-12-06 11:23

    def whites(a):
    return a[0:a.find(a.strip())]
    

    Basically, the my idea is:

    1. Find a strip of starting line
    2. Find a difference between starting line and stripped one

提交回复
热议问题