相关疑难解决方法(0)

用Python抓取一行的空格/缩进

基本上,如果我有一行以缩进开头的文本,那么获取该缩进并将其放入Python中的变量的最佳方法是什么?例如,如果该行是:

\t\tthis line has two tabs of indention
Run Code Online (Sandbox Code Playgroud)

然后它将返回'\ t\t'.或者,如果该行是:

    this line has four spaces of indention
Run Code Online (Sandbox Code Playgroud)

然后它将返回四个空格.

所以我想你可以说我只需要从第一个非空白字符到结尾的字符串中删除所有内容.思考?

python whitespace indentation

13
推荐指数
2
解决办法
5189
查看次数

检查字符串缩进?

我正在为一系列字符串构建分析器.我需要检查每条线的缩进量(通过制表符或空格).

每行只是文本编辑器中的一个字符串.如何检查字符串缩进多少?

或者更确切地说,也许我可以检查一个字符串之前有多少空格或\ t,但我不确定如何.

python lint analysis indentation

4
推荐指数
2
解决办法
6307
查看次数

标签 统计

indentation ×2

python ×2

analysis ×1

lint ×1

whitespace ×1