You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/preamble/python/python_best_practices.rst
+70-32Lines changed: 70 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,11 +52,22 @@ Minimalist package: something to start with
52
52
.. admonition:: In this step, we'll work on these.
53
53
54
54
.. code-block:: console
55
-
:emphasize-lines: 2,3
55
+
:emphasize-lines: 1-4
56
56
57
-
python/minimalist_package/
58
-
└── minimalist_package/
59
-
└── __init__.py
57
+
python/
58
+
`-- minimalist_package
59
+
|-- minimalist_package
60
+
| |-- __init__.py
61
+
| |-- _minimalist_class.py
62
+
| |-- minimalist_async
63
+
| | |-- __init__.py
64
+
| | |-- _unlikely_to_return.py
65
+
| | |-- async_await_example.py
66
+
| | `-- async_callback_example.py
67
+
| `-- minimalist_script.py
68
+
|-- setup.py
69
+
`-- test
70
+
`-- test_minimalist_class.py
60
71
61
72
62
73
First, let's make a folder for our project
@@ -94,19 +105,30 @@ The (empty) package is done!
94
105
Minimalist script
95
106
-----------------
96
107
97
-
.. admonition:: In this step, we'll work on this.
108
+
.. admonition:: In this step, we'll work on these.
98
109
99
110
.. code-block:: console
100
-
:emphasize-lines: 4
101
-
102
-
python/minimalist_package/
103
-
└── minimalist_package/
104
-
└── __init__.py
105
-
└── minimalist_script.py
111
+
:emphasize-lines: 11
112
+
113
+
python/
114
+
`-- minimalist_package
115
+
|-- minimalist_package
116
+
| |-- __init__.py
117
+
| |-- _minimalist_class.py
118
+
| |-- minimalist_async
119
+
| | |-- __init__.py
120
+
| | |-- _unlikely_to_return.py
121
+
| | |-- async_await_example.py
122
+
| | `-- async_callback_example.py
123
+
| `-- minimalist_script.py
124
+
|-- setup.py
125
+
`-- test
126
+
`-- test_minimalist_class.py
106
127
107
128
Let's start with a minimalist script that prints a string periodically,
108
-
as follows. Create a file in :file:`~/ros2_tutorials_preamble/python/minimalist_package/minimalist_package` called :file:`minimalist_script.py` with the following
109
-
contents.
129
+
as follows.
130
+
131
+
In the directory :file:`~/ros2_tutorials_preamble/python/minimalist_package/minimalist_package`, create the following file.
@@ -292,7 +323,7 @@ It might be parsing through jibber-jabber code in l__tcode lessons with weird C-
292
323
293
324
So, always pay attention to the naming of classes (`PascalCase <https://en.wiktionary.org/wiki/Pascal_case>`_), files and functions (`snake_case <https://en.wikipedia.org/wiki/Snake_case>`_), etc.
294
325
295
-
Thankfully, Python has a bunch of style rules builtin the language and :abbr:`PEP(Python Enhancement Proposal)`, such as `PEP8 <https://peps.python.org/pep-0008/>`_. Take this time to read it and get inspired by `The Zen of Python <https://peps.python.org/pep-0020/>`_
326
+
Thankfully, Python has a bunch of style rules builtin the language and :abbr:`PEP(Python Enhancement Proposal)`, such as `PEP8 <https://peps.python.org/pep-0008/>`_. Take this time to read it and get inspired by `The Zen of Python <https://peps.python.org/pep-0020/>`_.
296
327
297
328
.. _Type hints:
298
329
@@ -375,15 +406,22 @@ Unit tests: always test your code
375
406
.. admonition:: In this step, we'll work on these.
376
407
377
408
.. code-block:: console
378
-
:emphasize-lines: 6,7
379
-
380
-
python/minimalist_package/
381
-
└── minimalist_package/
382
-
└── __init__.py
383
-
└── minimalist_script.py
384
-
└── _minimalist_class.py
385
-
└── test/
386
-
└── test_minimalist_class.py
409
+
:emphasize-lines: 13,14
410
+
411
+
python/
412
+
`-- minimalist_package
413
+
|-- minimalist_package
414
+
| |-- __init__.py
415
+
| |-- _minimalist_class.py
416
+
| |-- minimalist_async
417
+
| | |-- __init__.py
418
+
| | |-- _unlikely_to_return.py
419
+
| | |-- async_await_example.py
420
+
| | `-- async_callback_example.py
421
+
| `-- minimalist_script.py
422
+
|-- setup.py
423
+
`-- test
424
+
`-- test_minimalist_class.py
387
425
388
426
`Unit testing <https://en.wikipedia.org/wiki/Unit_testing>`_ is a flag that has been waved by programming enthusiasts
0 commit comments