使調試與打印語句更簡單,更有效的Python庫:PyScribe

g6d7 9年前發布 | 15K 次閱讀 PyScribe Python開發

一個Python庫,使調試與打印語句更簡單,更有效。

687474703a2f2f692e696d6775722e636f6d2f4a5a59744964612e706e67.png

Installation

To install pyscribe:

$ pip install pyscribe

It may be necessary to have root privileges, in which case:

$ sudo pip install pyscribe

To uninstall:

$ pip uninstall pyscribe

Usage

  1. Includefrom pyscribe import pyscribeat the top of the files you are debugging.
  2. Initialize a variable of your choice topyscribe.Scriber()(E.g.:ps = pyscribe.Scriber())
  3. Make API calls as needed. (E.g.:ps.p(x))
  4. Run one of the following commands
  5. </ol>

    $ pyscribe myfile.py

    This is the equivalent of running$ python myfile.pywith all calls desugared.

    $ pyscribe myfile.py --extraargs "-u asdf"

    This is the equivalent of running$ python myfile.py -u asdfwith all calls desugared.

    $ pyscribe myfile.py --desugared

    This does not run anything, but rather outputs a myfile_desugared.py, which is intended to be run to debug.

    Argument Options

    • --extraargs-- Arguments intended to be passed to Python file when run. Must be called with --run set
    • --clean-- Produce a clean version of the file with all references to PyScribe removed
    • --desugared-- Produce a desugared version of the file with all API calls replaced with valid Python.
    • --log-- Save logs to a pyscribe_log.txt file along with timestamp.
    • </ul>

      API Calls

      • pyscribe.Scriber(labels=[])-- Initialize PyScribe. If you're scribing values with labels, you can filter by labels by passing in a list of the labels as strings.
      • pyscribe.p(object, label=None)-- Print the object value with relevant info dependent on type
      • pyscribe.iterscribe(object)-- Log the object value from inside a for or while loop which prints current iteration
      • pyscribe.watch(object)-- Log the object whenever its value changes
      • pyscribe.d(object, unit="*")-- Distinguish the log with a clear separator defined by the unit
      • </ul>

        Tests

        Test modules are in thetestsdirectory. Specific test cases are in these modules in the form oftestcase.py, and the test runner compares these withtestcase_correct.

        Example

        test.py:
        from pyscribe import pyscribe def main():
            ps = pyscribe.Scriber()
        
            ps.save_logs(True)
        
            x = 5 ps.p(x)
        
            bar = "foo" for i in xrange(5):
                bar += str(i)
                ps.iterscribe(bar)
        
            y = "hello" ps.p(y)
            ps.watch(y)
        
            y = "world" foo = 1234 ps.d(foo)
            ps.d(foo, unit="^")
        
            synonyms = {"clerk": "secretary", "student": "apprentice", "ground": "floor"}
            ps.p(synonyms) if __name__ == "__main__":
            main()

        項目主頁:http://www.baiduhome.net/lib/view/home/1420342141937

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