用于更改文件缩进的python实用程序。

indentp的Python项目详细描述


缩进

用于更改文件缩进的python脚本。

依赖关系

此软件包需要安装以下程序:

  1. Python

安装

安装可以通过克隆这个github存储库并运行./install.sh脚本来完成。

克隆github存储库:

git clone https://github.com/Thijsvanede/indentpy.git

安装脚本:

chmod +x ./install.sh
./install.sh

用法

python脚本可以以多种方式使用:

  1. 作为安装后的命令行程序。
  2. 作为源代码中的命令行程序。
  3. 作为一个python库。

对于所有用例,我们都给出了一个使用示例。

输入特殊字符

当您希望指定诸如\t\n之类的特殊字符时,可以通过组合ctrl+v和该字符的键将这些字符放入bash终端。示例:

  • \tctrl+v然后是tab
  • \nctrl+v然后是enter
  • \r\nctrl+v然后是crtl+r然后是ctrl+v然后是enter

命令行(已安装)

下面的帮助文件解释了缩进的用法。

Usage: indent [-h] [-w WRITE] [-o ORIG] [-t TO] [-d DELIM] file [file ...]

Change indentation of file(s).

positional arguments:
    file    File(s) for which to change indentation.

optional arguments:
    -h    Show this help text.
    -d    Line delimiter in original file    (optional, default='\n').
    -o    Indentation style in original file (optional, default='\t').
    -t    Indentation style in desired  file (optional, default='    ').
    -w    File to write output to (optional, default writes to inputfile).

示例

下面的示例以infile.py为例,将原始的\t缩进转换为4个空格,最后将其写入outfile.py

indent -w outfile.py -o '	' -t '    ', infile.py

命令行(来自源代码)

要从源代码运行程序,可以同时使用Python 2Python 3。下面的帮助文件解释了indent/indent.py的用法。

usage: indent.py [-h] [-w WRITE] [-o ORIG] [-t TO] [-d DELIM] file [file ...]

Indentation change tool.

positional arguments:
  file                      File(s) for which to change indentation.

optional arguments:
  -h, --help                show this help message and exit
  -w WRITE, --write WRITE   File to write output to (optional, if none is given,
                            change contents of file.
  -o ORIG, --orig ORIG      Indentation style in original file (optional, if none
                            is given, use '\t').
  -t TO, --to TO            Indentation style in desired file (optional, if none
                            is given, use 4 spaces).
  -d DELIM, --delim DELIM   Line delimiter in original file (optional, if none is
                            given, use '\n')

示例

下面的示例以infile.py为例,将原始的\t缩进转换为4个空格,最后将其写入outfile.py

python indent/indent.py -w outfile.py -o '	' -t '    ', infile.py

Python

待办事项

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Eclipse内存分析器(MAT):不显示当前正在运行的进程   java Apache Velocity:转义字符不能作为关联数组键用于PHP   不截断零的java格式十进制输出   在另一个类文件中调用时返回空值的java getter   java集合获取连接   java解析json使用Gson登录系统应用程序强制关闭   java DelferredResult带有两个请求的ajax请求   java可降低功耗,同时应使用无线   java BoxLayout无法共享错误?   java如何使用计时器制作闹钟   java使用OAuth2保护RESTWeb服务:一般原则   java在一个jframe上显示多个图像和按钮