一個使用像jquery選擇器的命令行工具來搜索python代碼

shudaoge 8年前發布 | 17K 次閱讀 Django jQuery Python開發

來自: https://github.com/caioariede/pyq

pyq

A command-line tool to search for Python code using jQuery-like selectors

Installation

pip install pyqtool

Usage

pyq2 [OPTIONS] SELECTOR [PATH]  # Python 2.x
pyq3 [OPTIONS] SELECTOR [PATH]  # Python 3.x

Available selectors

Type

class , def and import

Name

#classname or #methodname

Attributes

[name=value] , [name!=value] , [name*=value] , [name^=value] and [name$=value]

Pseudo-selectors

:extends(classname) and :not(selector)

Combinators

parent > child , parent descendant

Examples

Search for classes that extends the IntegerField class:

? pyq3 'class:extends(IntegerField)' django/forms
django/forms/fields.py:278 class FloatField(IntegerField):
django/forms/fields.py:315 class DecimalField(IntegerField):

Search for classes with the name FloatField :

? pyq3 'class[name=FloatField]' django/forms
django/forms/fields.py:278 class FloatField(IntegerField):

Search for methods under the FloatField class:

? pyq3 'class[name=FloatField] > def' django/forms
django/forms/fields.py:283     def to_python(self, value):
django/forms/fields.py:299     def validate(self, value):
django/forms/fields.py:308     def widget_attrs(self, widget):

Search for methods whose name starts with to under the FloatField class:

? pyq3 'class[name=FloatField] > def[name^=to]' django/forms
django/forms/fields.py:283     def to_python(self, value):

Search for import statements importing Counter :

? pyq3 'import[from=collections][name=Counter]' django/
django/apps/registry.py:5 from collections import Counter, OrderedDict, defaultdict
django/template/utils.py:3 from collections import Counter, OrderedDict
django/test/testcases.py:14 from collections import Counter
</article>

 本文由用戶 shudaoge 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!