用于在文件中注释输入/输出行的脚本。

fcomments的Python项目详细描述


PyPI versionPyVerLiccoverageBuild Status

F命令

管理命令行中的注释

安装

支持Python3.5+

fcomments在pypi

$ pip install fcomments

使用量

默认行为是切换行。意思是如果一个匹配的行 被注释,注释将被删除,如果行没有 评论评论将被添加。

指定-c标志确保匹配的行被注释掉 命令之后。flag-u的工作方式类似于 取消注释行。

资源调配

fromfcommentsimportCommenterLINES=[4,5,6]c=Commenter(path='path/to/file')c.comment_file(comment=True,lines=LINES)# ensure that lines 4-6 are commented outaction()# do sth: run tests, make migrations ..c.comment_file(uncomment=True,lines=LINES)# ensure that lines 4-6 are not commented

cli

# comment all lines in a file:
$ fcomments --comment --all path/to/file
$ fcomments -ca path/to/file
# comment lines 3 to 12:
$ fcomments --comment --lines=3-12 path/to/file
$ fcomments -cl3-12 path/to/file
–帮助
Usage: __main__.py [options] <path>

Examples:
       __main__.py -h                  --->  see help
       __main__.py -cl1,2 path/to/file  --->  comment out lines 1 and 2
       __main__.py -ul3-6 path/to/file  --->  uncomment lines 3 to 6 (inclusive)
       __main__.py -ac path/to/file     --->  comment out all lines
       __main__.py -au path/to/file     --->  uncomment all lines

       __main__.py --start-pattern='\s+operations\s?=\s?\[' --end-pattern='\s+\]' path/to/file
         --->  comment out everything inside the `operations` list:

         1| class Migration(...):
         2|
         3|     operations = [
         4| #       migrations(
         5| #           ...
         6| #       ),
         7|     ]


  Comment or uncomment lines in a file. Default behavior: do the oposite i.e.
if a line is commented - uncomment it, and vice versa. To make sure that the
matched lines will be [un]commented out - run with -[u]c option. If you don't
specify an --output, the original file (<path>) will be overwritten.

Options:
  -h, --help            show this help message and exit
  -c, --comment         comment lines [default: False]
  -u, --uncomment       uncomment lines [default: False]
  -a, --all             apply to all lines in file; suppresses -l option
                        [default: False]
  -l LINES, --lines=LINES
                        comma separeted string of line numbers [default: None]
  -s IN_PATTERN, --start-pattern=IN_PATTERN
                        pattern to match against the line before commented
                        section [default: None]
  -e OUT_PATTERN, --end-pattern=OUT_PATTERN
                        pattern to match against the first line after
                        commented section [default: None]
  -o OUTPUT, --output=OUTPUT
                        specify a path to output file [default: None]
  --symbol=COMMENT_SYMBOL
                        specify a string to use as comment [default: '#']

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

推荐PyPI第三方库


热门话题
java如何读取、验证和移动数据。csv文件?   用于在线蛇游戏的java解析scaing   java JavaFX:在窗口上移动元素(阶段)调整大小   mysql如何使用java中的IOUtils包在jsp中显示多个图像?   Java dateFormat不可解析日期异常   spring mvc java。执行单元测试时lang.AssertionError   java在一个webapp中运行多个调度器有什么问题吗?   JAVAlang.ArrayIndexOutofBounds异常:1未来。get()多线程   java使用MDC或spring boot中的任何过滤器屏蔽日志消息中的密码,而不使用logback。xml文件   与应用服务器的java AJP和SSL通信   java Hibernate更新列表中的特定对象   Java小程序:使用keylistener移动多边形   java访问是一个独立于MainActivity的进程   来自服务器的java重复密钥或完整性约束冲突消息:“列“volume”不能为null”   java是否有任何方法可以确保在Flink on job cancel with savepoint上通知所有检查点侦听器检查点完成?