Skip to content

Commit 292e42c

Browse files
Add tip for concatenating multiple (Python) substitutions (#5157)
Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
1 parent 71932cb commit 292e42c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

source/Tutorials/Intermediate/Launch/Using-Substitutions.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,26 @@ To do this, create following file in the ``launch`` folder of the ``launch_tutor
187187
:language: python
188188
:lines: 16-20
189189

190+
.. tip::
191+
192+
A list of substitutions or strings gets concatenated into a single string.
193+
This generally applies to anything that supports substitutions.
194+
195+
For example, with ``PathJoinSubstitution``, if the file name prefix depended on a launch argument named ``file``, a list of substitutions and strings could be used to create the file name:
196+
197+
.. code-block:: python
198+
199+
# Make sure to import LaunchConfiguration:
200+
# from launch.substitutions import LaunchConfiguration
201+
202+
PathJoinSubstitution([
203+
FindPackageShare('launch_tutorial'),
204+
'launch',
205+
[LaunchConfiguration('file', default='example_substitutions'), '_launch', '.py']
206+
])
207+
208+
In this case, by default, the last path component provided to ``PathJoinSubstitution`` would resolve to ``example_substitutions_launch.py`` and would then be joined with the other path components.
209+
190210
The ``launch_arguments`` dictionary with ``turtlesim_ns`` and ``use_provided_red`` arguments is passed to the ``IncludeLaunchDescription`` action.
191211
The ``TextSubstitution`` substitution is used to define the ``new_background_r`` argument with the value of the ``background_r`` key in the ``colors`` dictionary.
192212

0 commit comments

Comments
 (0)