diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2019-11-07 02:11:27 -0800 |
|---|---|---|
| committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2019-11-07 11:11:27 +0100 |
| commit | 26554cf5d1e96db10d0d5f4b69683a22fb82fdf8 (patch) | |
| tree | 57c685edd5ce651611e309e539a5eda80cd2f82b /docs/ref/contrib/gis/tutorial.txt | |
| parent | 77aa74cb70dd85497dbade6bc0f394aa41e88c94 (diff) | |
Fixed #29983 -- Replaced os.path() with pathlib.Path in project template and docs.
Thanks Curtis Maloney for the original patch.
Diffstat (limited to 'docs/ref/contrib/gis/tutorial.txt')
| -rw-r--r-- | docs/ref/contrib/gis/tutorial.txt | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/docs/ref/contrib/gis/tutorial.txt b/docs/ref/contrib/gis/tutorial.txt index 8fd8d60b62..25c2e35b1c 100644 --- a/docs/ref/contrib/gis/tutorial.txt +++ b/docs/ref/contrib/gis/tutorial.txt @@ -320,14 +320,12 @@ First, invoke the Django shell: $ python manage.py shell -If you downloaded the :ref:`worldborders` data earlier in the -tutorial, then you can determine its path using Python's built-in -``os`` module:: +If you downloaded the :ref:`worldborders` data earlier in the tutorial, then +you can determine its path using Python's :class:`pathlib.Path`:: - >>> import os + >>> from pathlib import Path >>> import world - >>> world_shp = os.path.abspath(os.path.join(os.path.dirname(world.__file__), - ... 'data', 'TM_WORLD_BORDERS-0.3.shp')) + >>> world_shp = Path(world.__file__).resolve().parent / 'data' / 'TM_WORLD_BORDERS-0.3.shp' Now, open the world borders shapefile using GeoDjango's :class:`~django.contrib.gis.gdal.DataSource` interface:: @@ -433,7 +431,7 @@ To import the data, use a LayerMapping in a Python script. Create a file called ``load.py`` inside the ``world`` application, with the following code:: - import os + from pathlib import Path from django.contrib.gis.utils import LayerMapping from .models import WorldBorder @@ -452,9 +450,7 @@ with the following code:: 'mpoly' : 'MULTIPOLYGON', } - world_shp = os.path.abspath( - os.path.join(os.path.dirname(__file__), 'data', 'TM_WORLD_BORDERS-0.3.shp'), - ) + world_shp = Path(__file__).resolve().parent / 'data' / 'TM_WORLD_BORDERS-0.3.shp' def run(verbose=True): lm = LayerMapping(WorldBorder, world_shp, world_mapping, transform=False) |
