就像赛德,但是巨蟒!

pyin的Python项目详细描述


就像赛德,但是Python!

https://travis-ci.org/geowurster/pyin.svg?branch=masterhttps://coveralls.io/repos/geowurster/pyin/badge.svg?branch=master

为什么?

有很多unix工具,比如用于处理文本的sedawk。 来自stdin或磁盘上的文件的数据,但是语法可能不友好,并且 有时用for循环编写一个非常简单的脚本会更容易 还有一些if语句。这个项目想让你陷入其中 for循环并让您编写自己的python表达式以快速获得任务 无需实际编写脚本、处理I/O等即可完成。

命令行界面

此项目旨在从包含的实用程序pyin中使用,尽管 底层的pyin.core.pmap()函数可以用于 非字符串对象。

Usage: pyin [OPTIONS] EXPRESSIONS...

  It's like sed, but Python!

  Map Python expressions across lines of text.  If an expression evaluates as
  'False' or 'None' then the current line is thrown away.  If an expression
  evaluates as 'True' then the next expression is evaluated.  If a list or
  dictionary is encountered it is JSON encoded.  All other objects are cast
  to string.

  Newline characters are stripped from the end of each line before processing
  and are added on write unless disabled with '--no-newline'.

  This utility employs 'eval()' internally but uses a limited scope to help
  prevent accidental side effects, but there are plenty of ways to get around
  this so don't pass anything through pyin that you wouldn't pass through
  'eval()'.

  Remove lines that do not contain a specific word:

      $ cat INFILE | pyin "'word' in line"
  Capitalize lines containing a specific word:

      $ cat INFILE | pyin "line.upper() if 'word' in line else line"
  Only print every other word from lines that contain a specific word:

      $ cat INFILE | pyin \
      > "'word' in line"\ # Get lines with 'word' in them
      > "line.split()[::2])" \  # Grab every other word
      > "' '.join(line)"         # Convert list from previous expr to str

  Process all input text as though it was a single line to replace carriage
  returns with the system newline character:

      $ cat INFILE | pyin --block \
      > "line.replace('\r\n', os.newline)"
  For a more in-depth explanation about exactly what's going on under the
  hood, see the the docstring in 'pyin.core.pmap()':

      $ python -c "help('pyin.core.pmap')"
Options:
  --version           Show the version and exit.
  -i, --infile PATH   Input text file. [default: stdin]
  -o, --outfile PATH  Output text file. [default: stdout]
  --block             Operate on all input text as though it was a single
                      line.
  --no-newline        Don't ensure each line ends with a newline character.
  --help              Show this message and exit.

安装

通过PIP:

$ pip install pyin

来自主分支:

$ git clone https://github.com/geowurster/pyin
$cd pyin && python setup.py install

py -x呢?

这个项目的大部分内容都是在很少了解py的情况下编写的,而不是 关于py -x的知识,其用途几乎完全相同。这个 这两个项目的主要区别在于pyin需要I/O和 对计算结果为TrueFalse

开发

安装:

$ git clone https://github.com/geowurster/pyin
$cd pyin
$ virtualenv venv &&source venv/bin/activate
$ pip install -e .\[dev\]$ py.test tests --cov pyin --cov-report term-missing

许可证

LICENSE.txt

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

推荐PyPI第三方库


热门话题
java SimpleCursorAdapter删除值   java结束while循环条件   java检查设备是否连接到特定网络   java组织。冬眠MappingException找不到逻辑名称为annotation getter的列   为什么java邮件中会抛出此异常?   加载SDK时发生java Eclipse错误   返回奇怪输出的Java数组   JavaXStream和对象类序列化   将枚举列表传递给namedQuery后出现java非法转换异常。Hibernate中的setParameter()   java Android studio不允许我在字符串上使用开关?   有没有办法从Java程序访问存储在Chrome中的cookie   java在枚举中构造实例而不修改枚举类   java Blackberry JDE FieldChangeListener   java修复错误:未报告的异常InterruptedException   java Spring数据JPA:findAll(具有规范和可分页)在计数查询中失败