将python缩进从空格转换为制表符的工具? [英] Tool to convert python indentation from spaces to tabs?

查看:217
本文介绍了将python缩进从空格转换为制表符的工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些.py文件,它们使用空格进行缩进,我想将它们转换为制表符.

I have a some .py files that use spaces for indentation, and I'd like to convert them to tabs.

我可以使用正则表达式轻松地将某些东西混在一起,但是我可以想到几种极端情况,这种方法可能会失败.是否有一种工具可以通过解析文件并确定缩进级别来实现此目的,就像python解释器一样?

I could easily hack together something using regexes, but I can think of several edge cases where this approach could fail. Is there a tool that does this by parsing the file and determining the indentation level the same way the python interpreter does?

推荐答案

Python包含相反的脚本(制表符).对我来说是C:\Python24\Tools\Scripts\reindent.py

Python includes a script for the opposite (tabs to spaces). It's C:\Python24\Tools\Scripts\reindent.py for me

这篇关于将python缩进从空格转换为制表符的工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆