From: Deepak Amin Date: Fri, 31 May 2019 18:17:35 +0000 (-0400) Subject: docs: Python3-ize the examples X-Git-Tag: 2.10.2~13^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1010%2Fhead;p=thirdparty%2Fjinja.git docs: Python3-ize the examples This commit updates the examples to conform to Python 3 instead of Python 2, as Python 3 is more acceptable these days. --- diff --git a/docs/api.rst b/docs/api.rst index fedc1c73..a45d1c43 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -46,7 +46,7 @@ To load a template from this environment you just have to call the To render it with some variables, just call the :meth:`render` method:: - print template.render(the='variables', go='here') + print(template.render(the='variables', go='here')) Using a template loader rather than passing strings to :class:`Template` or :meth:`Environment.from_string` has multiple advantages. Besides being @@ -834,7 +834,7 @@ Here a simple test that checks if a variable is a prime number:: def is_prime(n): if n == 2: return True - for i in xrange(2, int(math.ceil(math.sqrt(n))) + 1): + for i in range(2, int(math.ceil(math.sqrt(n))) + 1): if n % i == 0: return False return True diff --git a/docs/templates.rst b/docs/templates.rst index d10d5e67..ec4ba81d 100644 --- a/docs/templates.rst +++ b/docs/templates.rst @@ -572,7 +572,7 @@ As variables in templates retain their object properties, it is possible to iterate over containers like `dict`::
- {% for key, value in my_dict.iteritems() %} + {% for key, value in my_dict.items() %}
{{ key|e }}
{{ value|e }}
{% endfor %} @@ -1196,7 +1196,6 @@ but exists for completeness' sake. The following operators are supported: / Divide two numbers. The return value will be a floating point number. ``{{ 1 / 2 }}`` is ``{{ 0.5 }}``. - (Just like ``from __future__ import division``.) // Divide two numbers and return the truncated integer result.