diff options
| author | Claude Paroz <claude@2xlibre.net> | 2012-04-28 18:02:01 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2012-04-30 20:45:03 +0200 |
| commit | 596cb9c7e287abbb98c64974fb4944d522cb6b5a (patch) | |
| tree | e8ad5402dd233458b392d1822146bb1102ba74a6 /docs/topics | |
| parent | fe43ad5707d116bb1729bc17a24ca16c90ae040d (diff) | |
Replaced print statement by print function (forward compatibility syntax).
Diffstat (limited to 'docs/topics')
| -rw-r--r-- | docs/topics/auth.txt | 6 | ||||
| -rw-r--r-- | docs/topics/db/examples/many_to_many.txt | 4 | ||||
| -rw-r--r-- | docs/topics/db/queries.txt | 20 | ||||
| -rw-r--r-- | docs/topics/db/sql.txt | 8 | ||||
| -rw-r--r-- | docs/topics/forms/formsets.txt | 16 | ||||
| -rw-r--r-- | docs/topics/forms/media.txt | 16 | ||||
| -rw-r--r-- | docs/topics/forms/modelforms.txt | 4 | ||||
| -rw-r--r-- | docs/topics/http/urls.txt | 2 | ||||
| -rw-r--r-- | docs/topics/i18n/translation.txt | 2 | ||||
| -rw-r--r-- | docs/topics/install.txt | 2 | ||||
| -rw-r--r-- | docs/topics/signals.txt | 4 | ||||
| -rw-r--r-- | docs/topics/signing.txt | 2 |
12 files changed, 43 insertions, 43 deletions
diff --git a/docs/topics/auth.txt b/docs/topics/auth.txt index 8690b832e2..b067e241ff 100644 --- a/docs/topics/auth.txt +++ b/docs/topics/auth.txt @@ -714,11 +714,11 @@ Django provides two functions in :mod:`django.contrib.auth`: user = authenticate(username='john', password='secret') if user is not None: if user.is_active: - print "You provided a correct username and password!" + print("You provided a correct username and password!") else: - print "Your account has been disabled!" + print("Your account has been disabled!") else: - print "Your username and password were incorrect." + print("Your username and password were incorrect.") .. function:: login() diff --git a/docs/topics/db/examples/many_to_many.txt b/docs/topics/db/examples/many_to_many.txt index 1ad89e71bf..5a24027894 100644 --- a/docs/topics/db/examples/many_to_many.txt +++ b/docs/topics/db/examples/many_to_many.txt @@ -263,14 +263,14 @@ Bulk delete some Publications - references to deleted publications should go:: Bulk delete some articles - references to deleted objects should go:: >>> q = Article.objects.filter(headline__startswith='Django') - >>> print q + >>> print(q) [<Article: Django lets you build Web apps easily>] >>> q.delete() After the delete, the QuerySet cache needs to be cleared, and the referenced objects should be gone:: - >>> print q + >>> print(q) [] >>> p1.article_set.all() [<Article: NASA uses Python>] diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt index 0a67b9b486..7782f1c3ed 100644 --- a/docs/topics/db/queries.txt +++ b/docs/topics/db/queries.txt @@ -284,10 +284,10 @@ actually run the query until the :class:`~django.db.models.query.QuerySet` is >>> q = Entry.objects.filter(headline__startswith="What") >>> q = q.filter(pub_date__lte=datetime.now()) >>> q = q.exclude(body_text__icontains="food") - >>> print q + >>> print(q) Though this looks like three database hits, in fact it hits the database only -once, at the last line (``print q``). In general, the results of a +once, at the last line (``print(q)``). In general, the results of a :class:`~django.db.models.query.QuerySet` aren't fetched from the database until you "ask" for them. When you do, the :class:`~django.db.models.query.QuerySet` is *evaluated* by accessing the @@ -720,8 +720,8 @@ your :class:`~django.db.models.query.QuerySet`\s correctly. For example, the following will create two :class:`~django.db.models.query.QuerySet`\s, evaluate them, and throw them away:: - >>> print [e.headline for e in Entry.objects.all()] - >>> print [e.pub_date for e in Entry.objects.all()] + >>> print([e.headline for e in Entry.objects.all()]) + >>> print([e.pub_date for e in Entry.objects.all()]) That means the same database query will be executed twice, effectively doubling your database load. Also, there's a possibility the two lists may not include @@ -732,8 +732,8 @@ To avoid this problem, simply save the :class:`~django.db.models.query.QuerySet` and reuse it:: >>> queryset = Entry.objects.all() - >>> print [p.headline for p in queryset] # Evaluate the query set. - >>> print [p.pub_date for p in queryset] # Re-use the cache from the evaluation. + >>> print([p.headline for p in queryset]) # Evaluate the query set. + >>> print([p.pub_date for p in queryset]) # Re-use the cache from the evaluation. .. _complex-lookups-with-q: @@ -1055,16 +1055,16 @@ related object is accessed. Subsequent accesses to the foreign key on the same object instance are cached. Example:: >>> e = Entry.objects.get(id=2) - >>> print e.blog # Hits the database to retrieve the associated Blog. - >>> print e.blog # Doesn't hit the database; uses cached version. + >>> print(e.blog) # Hits the database to retrieve the associated Blog. + >>> print(e.blog) # Doesn't hit the database; uses cached version. Note that the :meth:`~django.db.models.query.QuerySet.select_related` :class:`~django.db.models.query.QuerySet` method recursively prepopulates the cache of all one-to-many relationships ahead of time. Example:: >>> e = Entry.objects.select_related().get(id=2) - >>> print e.blog # Doesn't hit the database; uses cached version. - >>> print e.blog # Doesn't hit the database; uses cached version. + >>> print(e.blog) # Doesn't hit the database; uses cached version. + >>> print(e.blog) # Doesn't hit the database; uses cached version. .. _backwards-related-objects: diff --git a/docs/topics/db/sql.txt b/docs/topics/db/sql.txt index 658dfdf859..2ac47170aa 100644 --- a/docs/topics/db/sql.txt +++ b/docs/topics/db/sql.txt @@ -40,7 +40,7 @@ This is best illustrated with an example. Suppose you've got the following model You could then execute custom SQL like so:: >>> for p in Person.objects.raw('SELECT * FROM myapp_person'): - ... print p + ... print(p) John Smith Jane Jones @@ -128,8 +128,8 @@ The ``Person`` objects returned by this query will be deferred model instances fields that are omitted from the query will be loaded on demand. For example:: >>> for p in Person.objects.raw('SELECT id, first_name FROM myapp_person'): - ... print p.first_name, # This will be retrieved by the original query - ... print p.last_name # This will be retrieved on demand + ... print(p.first_name, # This will be retrieved by the original query + ... p.last_name) # This will be retrieved on demand ... John Smith Jane Jones @@ -153,7 +153,7 @@ of people with their ages calculated by the database:: >>> people = Person.objects.raw('SELECT *, age(birth_date) AS age FROM myapp_person') >>> for p in people: - ... print "%s is %s." % (p.first_name, p.age) + ... print("%s is %s." % (p.first_name, p.age)) John is 37. Jane is 42. ... diff --git a/docs/topics/forms/formsets.txt b/docs/topics/forms/formsets.txt index b524c24ad2..ac45c50aa8 100644 --- a/docs/topics/forms/formsets.txt +++ b/docs/topics/forms/formsets.txt @@ -24,7 +24,7 @@ would with a regular form:: >>> formset = ArticleFormSet() >>> for form in formset: - ... print form.as_table() + ... print(form.as_table()) <tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" id="id_form-0-title" /></td></tr> <tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" id="id_form-0-pub_date" /></td></tr> @@ -42,7 +42,7 @@ the formset you iterated over the ``forms`` attribute:: >>> formset = ArticleFormSet() >>> for form in formset.forms: - ... print form.as_table() + ... print(form.as_table()) Iterating over ``formset.forms`` will render the forms in the order they were created. The default formset iterator also renders the forms @@ -71,7 +71,7 @@ example:: ... ]) >>> for form in formset: - ... print form.as_table() + ... print(form.as_table()) <tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" value="Django is now open source" id="id_form-0-title" /></td></tr> <tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" value="2008-05-12" id="id_form-0-pub_date" /></td></tr> <tr><th><label for="id_form-1-title">Title:</label></th><td><input type="text" name="form-1-title" id="id_form-1-title" /></td></tr> @@ -98,7 +98,7 @@ limit the maximum number of empty forms the formset will display:: >>> ArticleFormSet = formset_factory(ArticleForm, extra=2, max_num=1) >>> formset = ArticleFormset() >>> for form in formset: - ... print form.as_table() + ... print(form.as_table()) <tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" id="id_form-0-title" /></td></tr> <tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" id="id_form-0-pub_date" /></td></tr> @@ -283,7 +283,7 @@ Lets you create a formset with the ability to order:: ... {'title': u'Article #2', 'pub_date': datetime.date(2008, 5, 11)}, ... ]) >>> for form in formset: - ... print form.as_table() + ... print(form.as_table()) <tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" value="Article #1" id="id_form-0-title" /></td></tr> <tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" value="2008-05-10" id="id_form-0-pub_date" /></td></tr> <tr><th><label for="id_form-0-ORDER">Order:</label></th><td><input type="text" name="form-0-ORDER" value="1" id="id_form-0-ORDER" /></td></tr> @@ -321,7 +321,7 @@ happen when the user changes these values:: >>> formset.is_valid() True >>> for form in formset.ordered_forms: - ... print form.cleaned_data + ... print(form.cleaned_data) {'pub_date': datetime.date(2008, 5, 1), 'ORDER': 0, 'title': u'Article #3'} {'pub_date': datetime.date(2008, 5, 11), 'ORDER': 1, 'title': u'Article #2'} {'pub_date': datetime.date(2008, 5, 10), 'ORDER': 2, 'title': u'Article #1'} @@ -339,7 +339,7 @@ Lets you create a formset with the ability to delete:: ... {'title': u'Article #2', 'pub_date': datetime.date(2008, 5, 11)}, ... ]) >>> for form in formset: - .... print form.as_table() + .... print(form.as_table()) <input type="hidden" name="form-TOTAL_FORMS" value="3" id="id_form-TOTAL_FORMS" /><input type="hidden" name="form-INITIAL_FORMS" value="2" id="id_form-INITIAL_FORMS" /><input type="hidden" name="form-MAX_NUM_FORMS" id="id_form-MAX_NUM_FORMS" /> <tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" value="Article #1" id="id_form-0-title" /></td></tr> <tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" value="2008-05-10" id="id_form-0-pub_date" /></td></tr> @@ -393,7 +393,7 @@ default fields/attributes of the order and deletion fields:: >>> ArticleFormSet = formset_factory(ArticleForm, formset=BaseArticleFormSet) >>> formset = ArticleFormSet() >>> for form in formset: - ... print form.as_table() + ... print(form.as_table()) <tr><th><label for="id_form-0-title">Title:</label></th><td><input type="text" name="form-0-title" id="id_form-0-title" /></td></tr> <tr><th><label for="id_form-0-pub_date">Pub date:</label></th><td><input type="text" name="form-0-pub_date" id="id_form-0-pub_date" /></td></tr> <tr><th><label for="id_form-0-my_field">My field:</label></th><td><input type="text" name="form-0-my_field" id="id_form-0-my_field" /></td></tr> diff --git a/docs/topics/forms/media.txt b/docs/topics/forms/media.txt index 0eb3e91b3a..4399e7572c 100644 --- a/docs/topics/forms/media.txt +++ b/docs/topics/forms/media.txt @@ -64,7 +64,7 @@ named ``media``. The media for a CalendarWidget instance can be retrieved through this property:: >>> w = CalendarWidget() - >>> print w.media + >>> print(w.media) <link href="http://media.example.com/pretty.css" type="text/css" media="all" rel="stylesheet" /> <script type="text/javascript" src="http://media.example.com/animations.js"></script> <script type="text/javascript" src="http://media.example.com/actions.js"></script> @@ -139,7 +139,7 @@ basic Calendar widget from the example above:: ... js = ('whizbang.js',) >>> w = FancyCalendarWidget() - >>> print w.media + >>> print(w.media) <link href="http://media.example.com/pretty.css" type="text/css" media="all" rel="stylesheet" /> <link href="http://media.example.com/fancy.css" type="text/css" media="all" rel="stylesheet" /> <script type="text/javascript" src="http://media.example.com/animations.js"></script> @@ -159,7 +159,7 @@ declaration to the media declaration:: ... js = ('whizbang.js',) >>> w = FancyCalendarWidget() - >>> print w.media + >>> print(w.media) <link href="http://media.example.com/fancy.css" type="text/css" media="all" rel="stylesheet" /> <script type="text/javascript" src="http://media.example.com/whizbang.js"></script> @@ -221,7 +221,7 @@ was ``None``:: ... js = ('animations.js', 'http://othersite.com/actions.js') >>> w = CalendarWidget() - >>> print w.media + >>> print(w.media) <link href="/css/pretty.css" type="text/css" media="all" rel="stylesheet" /> <script type="text/javascript" src="http://uploads.example.com/animations.js"></script> <script type="text/javascript" src="http://othersite.com/actions.js"></script> @@ -229,7 +229,7 @@ was ``None``:: But if :setting:`STATIC_URL` is ``'http://static.example.com/'``:: >>> w = CalendarWidget() - >>> print w.media + >>> print(w.media) <link href="/css/pretty.css" type="text/css" media="all" rel="stylesheet" /> <script type="text/javascript" src="http://static.example.com/animations.js"></script> <script type="text/javascript" src="http://othersite.com/actions.js"></script> @@ -252,12 +252,12 @@ If you only want media of a particular type, you can use the subscript operator to filter out a medium of interest. For example:: >>> w = CalendarWidget() - >>> print w.media + >>> print(w.media) <link href="http://media.example.com/pretty.css" type="text/css" media="all" rel="stylesheet" /> <script type="text/javascript" src="http://media.example.com/animations.js"></script> <script type="text/javascript" src="http://media.example.com/actions.js"></script> - >>> print w.media['css'] + >>> print(w.media)['css'] <link href="http://media.example.com/pretty.css" type="text/css" media="all" rel="stylesheet" /> When you use the subscript operator, the value that is returned is a new @@ -282,7 +282,7 @@ the resulting Media object contains the union of the media from both files:: >>> w1 = CalendarWidget() >>> w2 = OtherWidget() - >>> print w1.media + w2.media + >>> print(w1.media + w2.media) <link href="http://media.example.com/pretty.css" type="text/css" media="all" rel="stylesheet" /> <script type="text/javascript" src="http://media.example.com/animations.js"></script> <script type="text/javascript" src="http://media.example.com/actions.js"></script> diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt index 6eadf217cc..df76b8094f 100644 --- a/docs/topics/forms/modelforms.txt +++ b/docs/topics/forms/modelforms.txt @@ -556,7 +556,7 @@ This will create a formset that is capable of working with the data associated with the ``Author`` model. It works just like a regular formset:: >>> formset = AuthorFormSet() - >>> print formset + >>> print(formset) <input type="hidden" name="form-TOTAL_FORMS" value="1" id="id_form-TOTAL_FORMS" /><input type="hidden" name="form-INITIAL_FORMS" value="0" id="id_form-INITIAL_FORMS" /><input type="hidden" name="form-MAX_NUM_FORMS" id="id_form-MAX_NUM_FORMS" /> <tr><th><label for="id_form-0-name">Name:</label></th><td><input id="id_form-0-name" type="text" name="form-0-name" maxlength="100" /></td></tr> <tr><th><label for="id_form-0-title">Title:</label></th><td><select name="form-0-title" id="id_form-0-title"> @@ -692,7 +692,7 @@ so long as the total number of forms does not exceed ``max_num``:: >>> AuthorFormSet = modelformset_factory(Author, max_num=4, extra=2) >>> formset = AuthorFormSet(queryset=Author.objects.order_by('name')) >>> for form in formset: - ... print form.as_table() + ... print(form.as_table()) <tr><th><label for="id_form-0-name">Name:</label></th><td><input id="id_form-0-name" type="text" name="form-0-name" value="Charles Baudelaire" maxlength="100" /><input type="hidden" name="form-0-id" value="1" id="id_form-0-id" /></td></tr> <tr><th><label for="id_form-1-name">Name:</label></th><td><input id="id_form-1-name" type="text" name="form-1-name" value="Paul Verlaine" maxlength="100" /><input type="hidden" name="form-1-id" value="3" id="id_form-1-id" /></td></tr> <tr><th><label for="id_form-2-name">Name:</label></th><td><input id="id_form-2-name" type="text" name="form-2-name" value="Walt Whitman" maxlength="100" /><input type="hidden" name="form-2-id" value="2" id="id_form-2-id" /></td></tr> diff --git a/docs/topics/http/urls.txt b/docs/topics/http/urls.txt index ee1d4e8616..2f272c5095 100644 --- a/docs/topics/http/urls.txt +++ b/docs/topics/http/urls.txt @@ -964,7 +964,7 @@ information about the URL pattern that matches a URL:: # Resolve a URL match = resolve('/some/path/') # Print the URL pattern that matches the URL - print match.url_name + print(match.url_name) A :class:`ResolverMatch` object can also be assigned to a triple:: diff --git a/docs/topics/i18n/translation.txt b/docs/topics/i18n/translation.txt index 052109b72c..4f56b251cf 100644 --- a/docs/topics/i18n/translation.txt +++ b/docs/topics/i18n/translation.txt @@ -436,7 +436,7 @@ languages:: >>> from django.utils.translation import get_language_info >>> li = get_language_info('de') - >>> print li['name'], li['name_local'], li['bidi'] + >>> print(li['name'], li['name_local'], li['bidi']) German Deutsch False The ``name`` and ``name_local`` attributes of the dictionary contain the name of diff --git a/docs/topics/install.txt b/docs/topics/install.txt index 2955f9d3b1..4fd745d22b 100644 --- a/docs/topics/install.txt +++ b/docs/topics/install.txt @@ -172,7 +172,7 @@ This file should also be located in your ``site-packages`` directory. .. code-block:: bash - python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" + python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())" (Note that this should be run from a shell prompt, not a Python interactive prompt.) diff --git a/docs/topics/signals.txt b/docs/topics/signals.txt index b4f70cf9e1..3ef68316a9 100644 --- a/docs/topics/signals.txt +++ b/docs/topics/signals.txt @@ -83,7 +83,7 @@ function or method: .. code-block:: python def my_callback(sender, **kwargs): - print "Request finished!" + print("Request finished!") Notice that the function takes a ``sender`` argument, along with wildcard keyword arguments (``**kwargs``); all signal handlers must take these arguments. @@ -125,7 +125,7 @@ receiver: @receiver(request_finished) def my_callback(sender, **kwargs): - print "Request finished!" + print("Request finished!") Now, our ``my_callback`` function will be called each time a request finishes. diff --git a/docs/topics/signing.txt b/docs/topics/signing.txt index f2ffd8a20c..07de97e2f3 100644 --- a/docs/topics/signing.txt +++ b/docs/topics/signing.txt @@ -64,7 +64,7 @@ If the signature or value have been altered in any way, a >>> try: ... original = signer.unsign(value) ... except signing.BadSignature: - ... print "Tampering detected!" + ... print("Tampering detected!") By default, the ``Signer`` class uses the :setting:`SECRET_KEY` setting to generate signatures. You can use a different secret by passing it to the |
