Code Monkey home page Code Monkey logo

pyformat.info's Introduction

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 https://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).

Running the tests

We use py.test to both test the functionality of the script generating the static HTML output as well as ensuring that the examples on the page are syntactically correct and produce the desired output.

The easiest way to run the tests on all supported Python versions is by using tox for which this repository contains a configuration file.

pyformat.info's People

Contributors

ulope avatar zerok avatar madphysicist avatar moreati avatar wdv4758h avatar jquast avatar williamjacksn avatar npappin-wsu avatar

Watchers

James Cloos avatar Artur Barseghyan avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.