PyFormat.info: Using % and .format() for great good!

With this project @ulope and @zerok wanted to document Python's awesome string formatting system with practical examples. While the official documentation on python.org contains a great deal of information regarding the actual syntax specification of the formatters and some examples, we felt it would be nice to see the new and old style of formatting side-by-side and provide even more practical examples.

What is Where?

The website you can find on http://pyformat.info is statically generated using the main.py. This script parses the test cases specified in tests/test_content.py which is more or less where all the content of the final site comes from.

Each test case can consist of following elements:

  • A optional title which is encoded as the first line of the docstring prefixed with a #
  • A short description on what is going on in the example which is what the rest of the docstring is used for
  • A value computation for the old-style formatter which is assigned to a variable called old_result
  • A value computation for the new-style formatter which is assigned to a variable called new_result
  • A handful of assertions. The last one that has a string on the right side is used as output on the website.
  • An optional setup section that is placed after the docstring and before the old_result asignment

If no old_result is provided this indicates that the feature is only available for the new formatting style and an appropriate message is rendered on the website.

How to Contribute

If you have another awesome example of what can be done with Python's formatters please create a new test-case in tests/test_content.py including a short info message about what is going on there as the docstring.

Once you have that, simply open a pull-request! Please make sure that you code is PEP8-compliant (except for the line length).

::...
免责声明:
当前网页内容, 由 大妈 ZoomQuiet 使用工具: ScrapBook :: Firefox Extension 人工从互联网中收集并分享;
内容版权归原作者所有;
本人对内容的有效性/合法性不承担任何强制性责任.
若有不妥, 欢迎评注提醒:

或是邮件反馈可也:
askdama[AT]googlegroups.com



自怼圈/年番新

DU21.4
关于 ~ DebugUself with DAMA ;-)


关注公众号, 持续获得相关各种嗯哼:
zoomquiet


粤ICP备18025058号-1
公安备案号: 44049002000656 ...::