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 | |
| parent | fe43ad5707d116bb1729bc17a24ca16c90ae040d (diff) | |
Replaced print statement by print function (forward compatibility syntax).
Diffstat (limited to 'docs')
30 files changed, 152 insertions, 152 deletions
diff --git a/docs/_ext/applyxrefs.py b/docs/_ext/applyxrefs.py index 3809088c1f..14d18bd856 100644 --- a/docs/_ext/applyxrefs.py +++ b/docs/_ext/applyxrefs.py @@ -77,12 +77,12 @@ def main(argv=None): target_found, lines = has_target(fn) if not target_found: if testing: - print '%s: %s' % (fn, lines[0]), + print('%s: %s' % (fn, lines[0])) else: - print "Adding xref to %s" % fn + print("Adding xref to %s" % fn) process_file(fn, lines) else: print "Skipping %s: already has a xref" % fn if __name__ == '__main__': - sys.exit(main())
\ No newline at end of file + sys.exit(main()) diff --git a/docs/_ext/literals_to_xrefs.py b/docs/_ext/literals_to_xrefs.py index 569193c72d..d1487ca729 100644 --- a/docs/_ext/literals_to_xrefs.py +++ b/docs/_ext/literals_to_xrefs.py @@ -136,10 +136,10 @@ def colorize(text='', opts=(), **kwargs): colorize('hello', fg='red', bg='blue', opts=('blink',)) colorize() colorize('goodbye', opts=('underscore',)) - print colorize('first line', fg='red', opts=('noreset',)) - print 'this should be red too' - print colorize('and so should this') - print 'this should not be red' + print(colorize('first line', fg='red', opts=('noreset',))) + print('this should be red too') + print(colorize('and so should this')) + print('this should not be red') """ color_names = ('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white') foreground = dict([(color_names[x], '3%s' % x) for x in range(8)]) @@ -168,4 +168,4 @@ if __name__ == '__main__': try: fixliterals(sys.argv[1]) except (KeyboardInterrupt, SystemExit): - print
\ No newline at end of file + print('') diff --git a/docs/howto/custom-model-fields.txt b/docs/howto/custom-model-fields.txt index 7f0ea3799d..5c2fed3b34 100644 --- a/docs/howto/custom-model-fields.txt +++ b/docs/howto/custom-model-fields.txt @@ -55,7 +55,7 @@ We'd like to be able to do things like this in our models (we assume the ``hand`` attribute on the model is an instance of ``Hand``):: example = MyModel.objects.get(pk=1) - print example.hand.north + print(example.hand.north) new_hand = Hand(north, east, south, west) example.hand = new_hand diff --git a/docs/intro/install.txt b/docs/intro/install.txt index 95f7b27396..41339b5f11 100644 --- a/docs/intro/install.txt +++ b/docs/intro/install.txt @@ -83,7 +83,7 @@ To verify that Django can be seen by Python, type ``python`` from your shell. Then at the Python prompt, try to import Django:: >>> import django - >>> print django.get_version() + >>> print(django.get_version()) 1.4 diff --git a/docs/ref/contrib/gis/db-api.txt b/docs/ref/contrib/gis/db-api.txt index 45698dd669..4cf65e513e 100644 --- a/docs/ref/contrib/gis/db-api.txt +++ b/docs/ref/contrib/gis/db-api.txt @@ -76,7 +76,7 @@ transform procedure:: >>> z = Zipcode(code=78212, poly=poly_3084) >>> z.save() >>> from django.db import connection - >>> print connection.queries[-1]['sql'] # printing the last SQL statement executed (requires DEBUG=True) + >>> print(connection.queries[-1]['sql']) # printing the last SQL statement executed (requires DEBUG=True) INSERT INTO "geoapp_zipcode" ("code", "poly") VALUES (78212, ST_Transform(ST_GeomFromWKB('\\001 ... ', 3084), 4326)) Thus, geometry parameters may be passed in using the ``GEOSGeometry`` object, WKT diff --git a/docs/ref/contrib/gis/gdal.txt b/docs/ref/contrib/gis/gdal.txt index 77c7c07618..5cd6187c6c 100644 --- a/docs/ref/contrib/gis/gdal.txt +++ b/docs/ref/contrib/gis/gdal.txt @@ -114,7 +114,7 @@ __ http://www.gdal.org/ogr/ogr_formats.html information about each layer in a :class:`DataSource`:: >>> for layer in ds: - ... print 'Layer "%s": %i %ss' % (layer.name, len(layer), layer.geom_type.name) + ... print('Layer "%s": %i %ss' % (layer.name, len(layer), layer.geom_type.name)) ... Layer "cities": 3 Points @@ -200,7 +200,7 @@ __ http://www.gdal.org/ogr/ogr_formats.html Property that returns the :class:`SpatialReference` associated with this layer:: - >>> print layer.srs + >>> print(layer.srs) GEOGCS["GCS_WGS_1984", DATUM["WGS_1984", SPHEROID["WGS_1984",6378137,298.257223563]], @@ -220,9 +220,9 @@ __ http://www.gdal.org/ogr/ogr_formats.html other than ``None``, only features that intersect the filter will be returned when iterating over the layer:: - >>> print layer.spatial_filter + >>> print(layer.spatial_filter) None - >>> print len(layer) + >>> print(len(layer)) 3 >>> [feat.get('Name') for feat in layer] ['Pueblo', 'Lawrence', 'Houston'] @@ -814,7 +814,7 @@ systems and coordinate transformation:: >>> gt1 = OGRGeomType(3) # Using an integer for the type >>> gt2 = OGRGeomType('Polygon') # Using a string >>> gt3 = OGRGeomType('POLYGON') # It's case-insensitive - >>> print gt1 == 3, gt1 == 'Polygon' # Equivalence works w/non-OGRGeomType objects + >>> print(gt1 == 3, gt1 == 'Polygon') # Equivalence works w/non-OGRGeomType objects True True .. attribute:: name @@ -927,19 +927,19 @@ Coordinate System Objects >>> wkt = 'GEOGCS["WGS 84", DATUM["WGS_1984, ... AUTHORITY["EPSG","4326"]]') >>> srs = SpatialReference(wkt) # could also use 'WGS84', or 4326 - >>> print srs['GEOGCS'] + >>> print(srs['GEOGCS']) WGS 84 - >>> print srs['DATUM'] + >>> print(srs['DATUM']) WGS_1984 - >>> print srs['AUTHORITY'] + >>> print(srs['AUTHORITY']) EPSG - >>> print srs['AUTHORITY', 1] # The authority value + >>> print(srs['AUTHORITY', 1]) # The authority value 4326 - >>> print srs['TOWGS84', 4] # the fourth value in this wkt + >>> print(srs['TOWGS84', 4]) # the fourth value in this wkt 0 - >>> print srs['UNIT|AUTHORITY'] # For the units authority, have to use the pipe symbol. + >>> print(srs['UNIT|AUTHORITY']) # For the units authority, have to use the pipe symbol. EPSG - >>> print srs['UNIT|AUTHORITY', 1] # The authority value for the units + >>> print(srs['UNIT|AUTHORITY', 1]) # The authority value for the units 9122 .. method:: attr_value(target, index=0) diff --git a/docs/ref/contrib/gis/geoquerysets.txt b/docs/ref/contrib/gis/geoquerysets.txt index 832f21e3e7..5bc9ab1f64 100644 --- a/docs/ref/contrib/gis/geoquerysets.txt +++ b/docs/ref/contrib/gis/geoquerysets.txt @@ -714,7 +714,7 @@ the distance from the `Tasmanian`__ city of Hobart to every other :class:`PointField` in the ``AustraliaCity`` queryset is calculated:: >>> pnt = AustraliaCity.objects.get(name='Hobart').point - >>> for city in AustraliaCity.objects.distance(pnt): print city.name, city.distance + >>> for city in AustraliaCity.objects.distance(pnt): print(city.name, city.distance) Wollongong 990071.220408 m Shellharbour 972804.613941 m Thirroul 1002334.36351 m @@ -874,9 +874,9 @@ Example:: >>> qs = Zipcode.objects.all().transform() # Transforms to WGS84 >>> qs = Zipcode.objects.all().transform(32140) # Transforming to "NAD83 / Texas South Central" - >>> print qs[0].poly.srid + >>> print(qs[0].poly.srid) 32140 - >>> print qs[0].poly + >>> print(qs[0].poly) POLYGON ((234055.1698884720099159 4937796.9232223574072123 ... ``translate`` @@ -990,7 +990,7 @@ Attaches a ``gml`` attribute to every model in the queryset that contains the Example:: >>> qs = Zipcode.objects.all().gml() - >>> print qs[0].gml + >>> print(qs[0].gml) <gml:Polygon srsName="EPSG:4326"><gml:OuterBoundaryIs>-147.78711,70.245363 ... -147.78711,70.245363</gml:OuterBoundaryIs></gml:Polygon> ===================== ===================================================== @@ -1023,7 +1023,7 @@ necessary. Example:: >>> qs = Zipcode.objects.all().kml() - >>> print qs[0].kml + >>> print(qs[0].kml) <Polygon><outerBoundaryIs><LinearRing><coordinates>-103.04135,36.217596,0 ... -103.04135,36.217596,0</coordinates></LinearRing></outerBoundaryIs></Polygon> ===================== ===================================================== @@ -1128,7 +1128,7 @@ lower left coordinate and the upper right coordinate. Example:: >>> qs = City.objects.filter(name__in=('Houston', 'Dallas')) - >>> print qs.extent() + >>> print(qs.extent()) (-96.8016128540039, 29.7633724212646, -95.3631439208984, 32.782058715820) ``extent3d`` @@ -1146,7 +1146,7 @@ the lower left coordinate and upper right coordinate. Example:: >>> qs = City.objects.filter(name__in=('Houston', 'Dallas')) - >>> print qs.extent3d() + >>> print(qs.extent3d()) (-96.8016128540039, 29.7633724212646, 0, -95.3631439208984, 32.782058715820, 0) ``make_line`` @@ -1161,7 +1161,7 @@ Returns a ``LineString`` constructed from the point field geometries in the Example:: - >>> print City.objects.filter(name__in=('Houston', 'Dallas')).make_line() + >>> print(City.objects.filter(name__in=('Houston', 'Dallas')).make_line()) LINESTRING (-95.3631510000000020 29.7633739999999989, -96.8016109999999941 32.7820570000000018) ``unionagg`` diff --git a/docs/ref/contrib/gis/geos.txt b/docs/ref/contrib/gis/geos.txt index 9fceda32d0..d3d9fe4442 100644 --- a/docs/ref/contrib/gis/geos.txt +++ b/docs/ref/contrib/gis/geos.txt @@ -231,7 +231,7 @@ Property that may be used to retrieve or set the SRID associated with the geometry. For example:: >>> pnt = Point(5, 23) - >>> print pnt.srid + >>> print(pnt.srid) None >>> pnt.srid = 4326 >>> pnt.srid diff --git a/docs/ref/contrib/gis/layermapping.txt b/docs/ref/contrib/gis/layermapping.txt index b0fb29e77a..dd0a41cbc0 100644 --- a/docs/ref/contrib/gis/layermapping.txt +++ b/docs/ref/contrib/gis/layermapping.txt @@ -39,13 +39,13 @@ Example >>> from django.contrib.gis.gdal import DataSource >>> ds = DataSource('test_poly.shp') >>> layer = ds[0] - >>> print layer.fields # Exploring the fields in the layer, we only want the 'str' field. + >>> print(layer.fields) # Exploring the fields in the layer, we only want the 'str' field. ['float', 'int', 'str'] - >>> print len(layer) # getting the number of features in the layer (should be 3) + >>> print(len(layer)) # getting the number of features in the layer (should be 3) 3 - >>> print layer.geom_type # Should be 'Polygon' + >>> print(layer.geom_type) # Should be 'Polygon' Polygon - >>> print layer.srs # WGS84 in WKT + >>> print(layer.srs) # WGS84 in WKT GEOGCS["GCS_WGS_1984", DATUM["WGS_1984", SPHEROID["WGS_1984",6378137,298.257223563]], diff --git a/docs/ref/contrib/gis/measure.txt b/docs/ref/contrib/gis/measure.txt index 6971788b4e..699677a50c 100644 --- a/docs/ref/contrib/gis/measure.txt +++ b/docs/ref/contrib/gis/measure.txt @@ -22,41 +22,41 @@ instantiated in units of kilometers (``km``) and miles (``mi``):: >>> from django.contrib.gis.measure import Distance, D >>> d1 = Distance(km=5) - >>> print d1 + >>> print(d1) 5.0 km >>> d2 = D(mi=5) # `D` is an alias for `Distance` - >>> print d2 + >>> print(d2) 5.0 mi Conversions are easy, just access the preferred unit attribute to get a converted distance quantity:: - >>> print d1.mi # Converting 5 kilometers to miles + >>> print(d1.mi) # Converting 5 kilometers to miles 3.10685596119 - >>> print d2.km # Converting 5 miles to kilometers + >>> print(d2.km) # Converting 5 miles to kilometers 8.04672 Moreover, arithmetic operations may be performed between the distance objects:: - >>> print d1 + d2 # Adding 5 miles to 5 kilometers + >>> print(d1 + d2) # Adding 5 miles to 5 kilometers 13.04672 km - >>> print d2 - d1 # Subtracting 5 kilometers from 5 miles + >>> print(d2 - d1) # Subtracting 5 kilometers from 5 miles 1.89314403881 mi Two :class:`Distance` objects multiplied together will yield an :class:`Area` object, which uses squared units of measure:: >>> a = d1 * d2 # Returns an Area object. - >>> print a + >>> print(a) 40.2336 sq_km To determine what the attribute abbreviation of a unit is, the ``unit_attname`` class method may be used:: - >>> print Distance.unit_attname('US Survey Foot') + >>> print(Distance.unit_attname('US Survey Foot')) survey_ft - >>> print Distance.unit_attname('centimeter') + >>> print(Distance.unit_attname('centimeter')) cm .. _supported_units: @@ -127,7 +127,7 @@ Measurement API Returns the distance value in units corresponding to the given unit attribute. For example:: - >>> print dist.km + >>> print(dist.km) 8.04672 .. classmethod:: unit_attname(unit_name) @@ -159,7 +159,7 @@ Measurement API Returns the area value in units corresponding to the given unit attribute. For example:: - >>> print a.sq_km + >>> print(a.sq_km) 12.949940551680001 .. classmethod:: unit_attname(unit_name) diff --git a/docs/ref/contrib/gis/tutorial.txt b/docs/ref/contrib/gis/tutorial.txt index 34014d7be4..395eac1821 100644 --- a/docs/ref/contrib/gis/tutorial.txt +++ b/docs/ref/contrib/gis/tutorial.txt @@ -362,24 +362,24 @@ Now, the world borders shapefile may be opened using GeoDjango's >>> from django.contrib.gis.gdal import DataSource >>> ds = DataSource(world_shp) - >>> print ds + >>> print(ds) / ... /geodjango/world/data/TM_WORLD_BORDERS-0.3.shp (ESRI Shapefile) Data source objects can have different layers of geospatial features; however, shapefiles are only allowed to have one layer:: - >>> print len(ds) + >>> print(len(ds)) 1 >>> lyr = ds[0] - >>> print lyr + >>> print(lyr) TM_WORLD_BORDERS-0.3 You can see what the geometry type of the layer is and how many features it contains:: - >>> print lyr.geom_type + >>> print(lyr.geom_type) Polygon - >>> print len(lyr) + >>> print(len(lyr)) 246 .. note:: @@ -397,7 +397,7 @@ system associated with it -- if it does, the ``srs`` attribute will return a :class:`~django.contrib.gis.gdal.SpatialReference` object:: >>> srs = lyr.srs - >>> print srs + >>> print(srs) GEOGCS["GCS_WGS_1984", DATUM["WGS_1984", SPHEROID["WGS_1984",6378137.0,298.257223563]], @@ -413,7 +413,7 @@ latitude. In addition, shapefiles also support attribute fields that may contain additional data. Here are the fields on the World Borders layer: - >>> print lyr.fields + >>> print(lyr.fields) ['FIPS', 'ISO2', 'ISO3', 'UN', 'NAME', 'AREA', 'POP2005', 'REGION', 'SUBREGION', 'LON', 'LAT'] Here we are examining the OGR types (e.g., whether a field is an integer or @@ -428,7 +428,7 @@ feature's attribute fields (whose **values** are accessed via ``get()`` method):: >>> for feat in lyr: - ... print feat.get('NAME'), feat.geom.num_points + ... print(feat.get('NAME'), feat.geom.num_points) ... Guernsey 18 Jersey 26 @@ -443,16 +443,16 @@ method):: And individual features may be retrieved by their feature ID:: >>> feat = lyr[234] - >>> print feat.get('NAME') + >>> print(feat.get('NAME')) San Marino Here the boundary geometry for San Marino is extracted and looking exported to WKT and GeoJSON:: >>> geom = feat.geom - >>> print geom.wkt + >>> print(geom.wkt) POLYGON ((12.415798 43.957954,12.450554 ... - >>> print geom.json + >>> print(geom.json) { "type": "Polygon", "coordinates": [ [ [ 12.415798, 43.957954 ], [ 12.450554, 43.979721 ], ... @@ -659,7 +659,7 @@ in transformation SQL, allowing the developer to work at a higher level of abstraction:: >>> qs = WorldBorder.objects.filter(mpoly__intersects=pnt) - >>> print qs.query # Generating the SQL + >>> print(qs.query) # Generating the SQL SELECT "world_worldborder"."id", "world_worldborder"."name", "world_worldborder"."area", "world_worldborder"."pop2005", "world_worldborder"."fips", "world_worldborder"."iso2", "world_worldborder"."iso3", "world_worldborder"."un", "world_worldborder"."region", diff --git a/docs/ref/contrib/syndication.txt b/docs/ref/contrib/syndication.txt index 754ac5843b..76c176e7b3 100644 --- a/docs/ref/contrib/syndication.txt +++ b/docs/ref/contrib/syndication.txt @@ -891,7 +891,7 @@ For example, to create an Atom 1.0 feed and print it to standard output:: ... link=u"http://www.example.com/entries/1/", ... pubdate=datetime.now(), ... description=u"<p>Today I had a Vienna Beef hot dog. It was pink, plump and perfect.</p>") - >>> print f.writeString('UTF-8') + >>> print(f.writeString('UTF-8')) <?xml version="1.0" encoding="UTF-8"?> <feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"> ... diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt index 86b6bb453e..a866fc550c 100644 --- a/docs/ref/forms/api.txt +++ b/docs/ref/forms/api.txt @@ -161,7 +161,7 @@ and the latter gets precedence:: ... url = forms.URLField() ... comment = forms.CharField() >>> f = CommentForm(initial={'name': 'instance'}, auto_id=False) - >>> print f + >>> print(f) <tr><th>Name:</th><td><input type="text" name="name" value="instance" /></td></tr> <tr><th>Url:</th><td><input type="text" name="url" /></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr> @@ -266,7 +266,7 @@ The second task of a ``Form`` object is to render itself as HTML. To do so, simply ``print`` it:: >>> f = ContactForm() - >>> print f + >>> print(f) <tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" /></td></tr> <tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" /></td></tr> <tr><th><label for="id_sender">Sender:</label></th><td><input type="text" name="sender" id="id_sender" /></td></tr> @@ -283,7 +283,7 @@ include ``checked="checked"`` if appropriate:: ... 'sender': 'foo@example.com', ... 'cc_myself': True} >>> f = ContactForm(data) - >>> print f + >>> print(f) <tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" value="hello" /></td></tr> <tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" value="Hi there" /></td></tr> <tr><th><label for="id_sender">Sender:</label></th><td><input type="text" name="sender" id="id_sender" value="foo@example.com" /></td></tr> @@ -331,7 +331,7 @@ a form object, and each rendering method returns a Unicode object. >>> f = ContactForm() >>> f.as_p() u'<p><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></p>\n<p><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></p>\n<p><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></p>\n<p><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></p>' - >>> print f.as_p() + >>> print(f.as_p()) <p><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></p> <p><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></p> <p><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></p> @@ -350,7 +350,7 @@ a form object, and each rendering method returns a Unicode object. >>> f = ContactForm() >>> f.as_ul() u'<li><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></li>\n<li><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></li>\n<li><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></li>\n<li><label for="id_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_cc_myself" /></li>' - >>> print f.as_ul() + >>> print(f.as_ul()) <li><label for="id_subject">Subject:</label> <input id="id_subject" type="text" name="subject" maxlength="100" /></li> <li><label for="id_message">Message:</label> <input type="text" name="message" id="id_message" /></li> <li><label for="id_sender">Sender:</label> <input type="text" name="sender" id="id_sender" /></li> @@ -368,7 +368,7 @@ a form object, and each rendering method returns a Unicode object. >>> f = ContactForm() >>> f.as_table() u'<tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" /></td></tr>\n<tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" /></td></tr>\n<tr><th><label for="id_sender">Sender:</label></th><td><input type="text" name="sender" id="id_sender" /></td></tr>\n<tr><th><label for="id_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_cc_myself" /></td></tr>' - >>> print f.as_table() + >>> print(f.as_table()) <tr><th><label for="id_subject">Subject:</label></th><td><input id="id_subject" type="text" name="subject" maxlength="100" /></td></tr> <tr><th><label for="id_message">Message:</label></th><td><input type="text" name="message" id="id_message" /></td></tr> <tr><th><label for="id_sender">Sender:</label></th><td><input type="text" name="sender" id="id_sender" /></td></tr> @@ -398,7 +398,7 @@ Once you've done that, rows will be given ``"error"`` and/or ``"required"`` classes, as needed. The HTML will look something like:: >>> f = ContactForm(data) - >>> print f.as_table() + >>> print(f.as_table()) <tr class="required"><th><label for="id_subject">Subject:</label> ... <tr class="required"><th><label for="id_message">Message:</label> ... <tr class="required error"><th><label for="id_sender">Sender:</label> ... @@ -426,17 +426,17 @@ If ``auto_id`` is ``False``, then the form output will not include ``<label>`` tags nor ``id`` attributes:: >>> f = ContactForm(auto_id=False) - >>> print f.as_table() + >>> print(f.as_table()) <tr><th>Subject:</th><td><input type="text" name="subject" maxlength="100" /></td></tr> <tr><th>Message:</th><td><input type="text" name="message" /></td></tr> <tr><th>Sender:</th><td><input type="text" name="sender" /></td></tr> <tr><th>Cc myself:</th><td><input type="checkbox" name="cc_myself" /></td></tr> - >>> print f.as_ul() + >>> print(f.as_ul()) <li>Subject: <input type="text" name="subject" maxlength="100" /></li> <li>Message: <input type="text" name="message" /></li> <li>Sender: <input type="text" name="sender" /></li> <li>Cc myself: <input type="checkbox" name="cc_myself" /></li> - >>> print f.as_p() + >>> print(f.as_p()) <p>Subject: <input type="text" name="subject" maxlength="100" /></p> <p>Message: <input type="text" name="message" /></p> <p>Sender: <input type="text" name="sender" /></p> @@ -447,17 +447,17 @@ If ``auto_id`` is set to ``True``, then the form output *will* include field:: >>> f = ContactForm(auto_id=True) - >>> print f.as_table() + >>> print(f.as_table()) <tr><th><label for="subject">Subject:</label></th><td><input id="subject" type="text" name="subject" maxlength="100" /></td></tr> <tr><th><label for="message">Message:</label></th><td><input type="text" name="message" id="message" /></td></tr> <tr><th><label for="sender">Sender:</label></th><td><input type="text" name="sender" id="sender" /></td></tr> <tr><th><label for="cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="cc_myself" /></td></tr> - >>> print f.as_ul() + >>> print(f.as_ul()) <li><label for="subject">Subject:</label> <input id="subject" type="text" name="subject" maxlength="100" /></li> <li><label for="message">Message:</label> <input type="text" name="message" id="message" /></li> <li><label for="sender">Sender:</label> <input type="text" name="sender" id="sender" /></li> <li><label for="cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="cc_myself" /></li> - >>> print f.as_p() + >>> print(f.as_p()) <p><label for="subject">Subject:</label> <input id="subject" type="text" name="subject" maxlength="100" /></p> <p><label for="message">Message:</label> <input type="text" name="message" id="message" /></p> <p><label for="sender">Sender:</label> <input type="text" name="sender" id="sender" /></p> @@ -470,17 +470,17 @@ attributes based on the format string. For example, for a format string ``'field_subject'``. Continuing our example:: >>> f = ContactForm(auto_id='id_for_%s') - >>> print f.as_table() + >>> print(f.as_table()) <tr><th><label for="id_for_subject">Subject:</label></th><td><input id="id_for_subject" type="text" name="subject" maxlength="100" /></td></tr> <tr><th><label for="id_for_message">Message:</label></th><td><input type="text" name="message" id="id_for_message" /></td></tr> <tr><th><label for="id_for_sender">Sender:</label></th><td><input type="text" name="sender" id="id_for_sender" /></td></tr> <tr><th><label for="id_for_cc_myself">Cc myself:</label></th><td><input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></td></tr> - >>> print f.as_ul() + >>> print(f.as_ul()) <li><label for="id_for_subject">Subject:</label> <input id="id_for_subject" type="text" name="subject" maxlength="100" /></li> <li><label for="id_for_message">Message:</label> <input type="text" name="message" id="id_for_message" /></li> <li><label for="id_for_sender">Sender:</label> <input type="text" name="sender" id="id_for_sender" /></li> <li><label for="id_for_cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></li> - >>> print f.as_p() + >>> print(f.as_p()) <p><label for="id_for_subject">Subject:</label> <input id="id_for_subject" type="text" name="subject" maxlength="100" /></p> <p><label for="id_for_message">Message:</label> <input type="text" name="message" id="id_for_message" /></p> <p><label for="id_for_sender">Sender:</label> <input type="text" name="sender" id="id_for_sender" /></p> @@ -496,13 +496,13 @@ rendered. It's possible to change the colon to another character, or omit it entirely, using the ``label_suffix`` parameter:: >>> f = ContactForm(auto_id='id_for_%s', label_suffix='') - >>> print f.as_ul() + >>> print(f.as_ul()) <li><label for="id_for_subject">Subject</label> <input id="id_for_subject" type="text" name="subject" maxlength="100" /></li> <li><label for="id_for_message">Message</label> <input type="text" name="message" id="id_for_message" /></li> <li><label for="id_for_sender">Sender</label> <input type="text" name="sender" id="id_for_sender" /></li> <li><label for="id_for_cc_myself">Cc myself</label> <input type="checkbox" name="cc_myself" id="id_for_cc_myself" /></li> >>> f = ContactForm(auto_id='id_for_%s', label_suffix=' ->') - >>> print f.as_ul() + >>> print(f.as_ul()) <li><label for="id_for_subject">Subject -></label> <input id="id_for_subject" type="text" name="subject" maxlength="100" /></li> <li><label for="id_for_message">Message -></label> <input type="text" name="message" id="id_for_message" /></li> <li><label for="id_for_sender">Sender -></label> <input type="text" name="sender" id="id_for_sender" /></li> @@ -534,17 +534,17 @@ method you're using:: ... 'sender': 'invalid email address', ... 'cc_myself': True} >>> f = ContactForm(data, auto_id=False) - >>> print f.as_table() + >>> print(f.as_table()) <tr><th>Subject:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="subject" maxlength="100" /></td></tr> <tr><th>Message:</th><td><input type="text" name="message" value="Hi there" /></td></tr> <tr><th>Sender:</th><td><ul class="errorlist"><li>Enter a valid e-mail address.</li></ul><input type="text" name="sender" value="invalid email address" /></td></tr> <tr><th>Cc myself:</th><td><input checked="checked" type="checkbox" name="cc_myself" /></td></tr> - >>> print f.as_ul() + >>> print(f.as_ul()) <li><ul class="errorlist"><li>This field is required.</li></ul>Subject: <input type="text" name="subject" maxlength="100" /></li> <li>Message: <input type="text" name="message" value="Hi there" /></li> <li><ul class="errorlist"><li>Enter a valid e-mail address.</li></ul>Sender: <input type="text" name="sender" value="invalid email address" /></li> <li>Cc myself: <input checked="checked" type="checkbox" name="cc_myself" /></li> - >>> print f.as_p() + >>> print(f.as_p()) <p><ul class="errorlist"><li>This field is required.</li></ul></p> <p>Subject: <input type="text" name="subject" maxlength="100" /></p> <p>Message: <input type="text" name="message" value="Hi there" /></p> @@ -593,13 +593,13 @@ To retrieve a single ``BoundField``, use dictionary lookup syntax on your form using the field's name as the key:: >>> form = ContactForm() - >>> print form['subject'] + >>> print(form['subject']) <input id="id_subject" type="text" name="subject" maxlength="100" /> To retrieve all ``BoundField`` objects, iterate the form:: >>> form = ContactForm() - >>> for boundfield in form: print boundfield + >>> for boundfield in form: print(boundfield) <input id="id_subject" type="text" name="subject" maxlength="100" /> <input type="text" name="message" id="id_message" /> <input type="text" name="sender" id="id_sender" /> @@ -608,10 +608,10 @@ To retrieve all ``BoundField`` objects, iterate the form:: The field-specific output honors the form object's ``auto_id`` setting:: >>> f = ContactForm(auto_id=False) - >>> print f['message'] + >>> print(f['message']) <input type="text" name="message" /> >>> f = ContactForm(auto_id='id_%s') - >>> print f['message'] + >>> print(f['message']) <input type="text" name="message" id="id_message" /> For a field's list of errors, access the field's ``errors`` attribute. @@ -623,15 +623,15 @@ For a field's list of errors, access the field's ``errors`` attribute. >>> data = {'subject': 'hi', 'message': '', 'sender': '', 'cc_myself': ''} >>> f = ContactForm(data, auto_id=False) - >>> print f['message'] + >>> print(f['message']) <input type="text" name="message" /> >>> f['message'].errors [u'This field is required.'] - >>> print f['message'].errors + >>> print(f['message'].errors) <ul class="errorlist"><li>This field is required.</li></ul> >>> f['subject'].errors [] - >>> print f['subject'].errors + >>> print(f['subject'].errors) >>> str(f['subject'].errors) '' @@ -667,9 +667,9 @@ by a ``Widget``:: >>> initial = {'subject': 'welcome'} >>> unbound_form = ContactForm(initial=initial) >>> bound_form = ContactForm(data, initial=initial) - >>> print unbound_form['subject'].value() + >>> print(unbound_form['subject'].value()) welcome - >>> print bound_form['subject'].value() + >>> print(bound_form['subject'].value()) hi .. _binding-uploaded-files: @@ -753,7 +753,7 @@ fields are ordered first:: >>> class ContactFormWithPriority(ContactForm): ... priority = forms.CharField() >>> f = ContactFormWithPriority(auto_id=False) - >>> print f.as_ul() + >>> print(f.as_ul()) <li>Subject: <input type="text" name="subject" maxlength="100" /></li> <li>Message: <input type="text" name="message" /></li> <li>Sender: <input type="text" name="sender" /></li> @@ -773,7 +773,7 @@ classes:: >>> class BeatleForm(PersonForm, InstrumentForm): ... haircut_type = CharField() >>> b = BeatleForm(auto_id=False) - >>> print b.as_ul() + >>> print(b.as_ul()) <li>First name: <input type="text" name="first_name" /></li> <li>Last name: <input type="text" name="last_name" /></li> <li>Instrument: <input type="text" name="instrument" /></li> @@ -791,9 +791,9 @@ You can put several Django forms inside one ``<form>`` tag. To give each >>> mother = PersonForm(prefix="mother") >>> father = PersonForm(prefix="father") - >>> print mother.as_ul() + >>> print(mother.as_ul()) <li><label for="id_mother-first_name">First name:</label> <input type="text" name="mother-first_name" id="id_mother-first_name" /></li> <li><label for="id_mother-last_name">Last name:</label> <input type="text" name="mother-last_name" id="id_mother-last_name" /></li> - >>> print father.as_ul() + >>> print(father.as_ul()) <li><label for="id_father-first_name">First name:</label> <input type="text" name="father-first_name" id="id_father-first_name" /></li> <li><label for="id_father-last_name">Last name:</label> <input type="text" name="father-last_name" id="id_father-last_name" /></li> diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt index fa5800692f..0da891ec4b 100644 --- a/docs/ref/forms/fields.txt +++ b/docs/ref/forms/fields.txt @@ -112,7 +112,7 @@ We've specified ``auto_id=False`` to simplify the output:: ... url = forms.URLField(label='Your Web site', required=False) ... comment = forms.CharField() >>> f = CommentForm(auto_id=False) - >>> print f + >>> print(f) <tr><th>Your name:</th><td><input type="text" name="name" /></td></tr> <tr><th>Your Web site:</th><td><input type="text" name="url" /></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr> @@ -135,7 +135,7 @@ field is initialized to a particular value. For example:: ... url = forms.URLField(initial='http://') ... comment = forms.CharField() >>> f = CommentForm(auto_id=False) - >>> print f + >>> print(f) <tr><th>Name:</th><td><input type="text" name="name" value="Your name" /></td></tr> <tr><th>Url:</th><td><input type="text" name="url" value="http://" /></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr> @@ -150,7 +150,7 @@ and the HTML output will include any validation errors:: ... comment = forms.CharField() >>> default_data = {'name': 'Your name', 'url': 'http://'} >>> f = CommentForm(default_data, auto_id=False) - >>> print f + >>> print(f) <tr><th>Name:</th><td><input type="text" name="name" value="Your name" /></td></tr> <tr><th>Url:</th><td><ul class="errorlist"><li>Enter a valid URL.</li></ul><input type="text" name="url" value="http://" /></td></tr> <tr><th>Comment:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="comment" /></td></tr> @@ -179,7 +179,7 @@ Instead of a constant, you can also pass any callable:: >>> import datetime >>> class DateForm(forms.Form): ... day = forms.DateField(initial=datetime.date.today) - >>> print DateForm() + >>> print(DateForm()) <tr><th>Day:</th><td><input type="text" name="day" value="12/23/2008" /><td></tr> The callable will be evaluated only when the unbound form is displayed, not when it is defined. @@ -211,17 +211,17 @@ fields. We've specified ``auto_id=False`` to simplify the output:: ... sender = forms.EmailField(help_text='A valid email address, please.') ... cc_myself = forms.BooleanField(required=False) >>> f = HelpTextContactForm(auto_id=False) - >>> print f.as_table() + >>> print(f.as_table()) <tr><th>Subject:</th><td><input type="text" name="subject" maxlength="100" /><br /><span class="helptext">100 characters max.</span></td></tr> <tr><th>Message:</th><td><input type="text" name="message" /></td></tr> <tr><th>Sender:</th><td><input type="text" name="sender" /><br />A valid email address, please.</td></tr> <tr><th>Cc myself:</th><td><input type="checkbox" name="cc_myself" /></td></tr> - >>> print f.as_ul() + >>> print(f.as_ul())) <li>Subject: <input type="text" name="subject" maxlength="100" /> <span class="helptext">100 characters max.</span></li> <li>Message: <input type="text" name="message" /></li> <li>Sender: <input type="text" name="sender" /> A valid email address, please.</li> <li>Cc myself: <input type="checkbox" name="cc_myself" /></li> - >>> print f.as_p() + >>> print(f.as_p()) <p>Subject: <input type="text" name="subject" maxlength="100" /> <span class="helptext">100 characters max.</span></p> <p>Message: <input type="text" name="message" /></p> <p>Sender: <input type="text" name="sender" /> A valid email address, please.</p> diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt index 8eaf946825..3c84be50a6 100644 --- a/docs/ref/models/instances.txt +++ b/docs/ref/models/instances.txt @@ -327,7 +327,7 @@ Once the object has been saved, you must reload the object in order to access the actual value that was applied to the updated field:: >>> product = Products.objects.get(pk=product.pk) - >>> print product.number_sold + >>> print(product.number_sold) 42 For more details, see the documentation on :ref:`F() expressions diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt index b20c6e34e5..050598a532 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -29,7 +29,7 @@ You can evaluate a ``QuerySet`` in the following ways: the headline of all entries in the database:: for e in Entry.objects.all(): - print e.headline + print(e.headline) * **Slicing.** As explained in :ref:`limiting-querysets`, a ``QuerySet`` can be sliced, using Python's array-slicing syntax. Slicing an unevaluated @@ -71,7 +71,7 @@ You can evaluate a ``QuerySet`` in the following ways: ``True``, otherwise ``False``. For example:: if Entry.objects.filter(headline="Test"): - print "There is at least one Entry with the headline Test" + print("There is at least one Entry with the headline Test") Note: *Don't* use this if all you want to do is determine if at least one result exists, and don't need the actual objects. It's more efficient to @@ -1251,7 +1251,7 @@ The :exc:`~django.core.exceptions.DoesNotExist` exception inherits from e = Entry.objects.get(id=3) b = Blog.objects.get(id=1) except ObjectDoesNotExist: - print "Either the entry or blog doesn't exist." + print("Either the entry or blog doesn't exist.") create ~~~~~~ diff --git a/docs/ref/template-response.txt b/docs/ref/template-response.txt index a432312fd2..9e09077adc 100644 --- a/docs/ref/template-response.txt +++ b/docs/ref/template-response.txt @@ -215,18 +215,18 @@ the content of the response manually:: # Set up a rendered TemplateResponse >>> t = TemplateResponse(request, 'original.html', {}) >>> t.render() - >>> print t.content + >>> print(t.content) Original content # Re-rendering doesn't change content >>> t.template_name = 'new.html' >>> t.render() - >>> print t.content + >>> print(t.content) Original content # Assigning content does change, no render() call required >>> t.content = t.rendered_content - >>> print t.content + >>> print(t.content) New content Post-render callbacks diff --git a/docs/ref/templates/api.txt b/docs/ref/templates/api.txt index 134f90c38c..aece572e07 100644 --- a/docs/ref/templates/api.txt +++ b/docs/ref/templates/api.txt @@ -69,7 +69,7 @@ takes one argument -- the raw template code:: >>> from django.template import Template >>> t = Template("My name is {{ my_name }}.") - >>> print t + >>> print(t) <django.template.Template instance> .. admonition:: Behind the scenes 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 |
