recipe-66433.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:code 作者: ActiveState 项目源码 文件源码
def entab(temp, tab_width=4, all=0):

        #if all is true, every time tab_width number of spaces are found next
        #to each other, they are converted to a tab.  If false, only those at
        #the beginning of the line are converted.  Default is false.

        if all:
                temp = re.sub(r" {" + `tab_width` + r"}", r"\t", temp)
        else:
                patt = re.compile(r"^ {" + `tab_width` + r"}", re.M)
                temp, count = patt.subn(r"\t", temp)
                i = 1
                while count > 0:
                        #this only loops a few times, at most six or seven times on
                        #heavily indented code
                        subpatt = re.compile(r"^\t{" + `i` + r"} {" + `tab_width` + r"}", re.M)
                        temp, count = subpatt.subn("\t"*(i+1), temp)
                        i += 1
        return temp
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号