# what does this mean?  \['tag\_Environment\_%s' % args.environment\]

**URL:** <https://forum.ansible.com/t/what-does-this-mean-tag-environment-s-args-environment/18085>\
**Category:** Ansible Project\
**Created:** [April 25, 2015, 6:37am UTC](https://forum.ansible.com/t/what-does-this-mean-tag-environment-s-args-environment/18085 "2015-04-25T06:37:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Stivers](https://avatars.discourse-cdn.com/v4/letter/p/b9e5f3/32.png) [@Paul\_Stivers](https://forum.ansible.com/u/Paul_Stivers)\
**Post date:** [April 25, 2015, 6:37am UTC](https://forum.ansible.com/t/what-does-this-mean-tag-environment-s-args-environment/18085/1 "2015-04-25T06:37:41Z")

</div>

This may be as much a Python question as an Ansible question. This is a function in a deploy script.  
I'm trying to understand what "['tag\_Environment\_%s' % args.environment]" means.  
Problem is I don't know enough about the syntax to even google the right topic. Any help?  
Either an explanation, or pointer to a url, or a topic to search, would be very much appreciated.

Paul

from ansible.inventory import Inventory

def set\_inventory(args):  
&nbsp;&nbsp;&nbsp;&nbsp;subsets = ['tag\_Environment\_%s' % args.environment]  
&nbsp;&nbsp;&nbsp;&nbsp;if args.subset:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;subsets.append(args.subset)

&nbsp;&nbsp;&nbsp;&nbsp;inventory = Inventory(args.inventory)  
&nbsp;&nbsp;&nbsp;&nbsp;inventory.subset(":&".join(subsets))  
&nbsp;&nbsp;&nbsp;&nbsp;return inventory code here...

---

<div class="post-metadata">

**Author:** ![Paul\_Totterman](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Paul\_Totterman](https://forum.ansible.com/u/Paul_Totterman)\
**Post date:** [April 25, 2015, 2:58pm UTC](https://forum.ansible.com/t/what-does-this-mean-tag-environment-s-args-environment/18085/2 "2015-04-25T14:58:11Z")

</div>

> I’m trying to understand what “[‘tag\_Environment\_%s’ % args.environment]” means.

is a list literal in Python. [1, 2, 3] can also be written as list(1, 2, 3)

% is the string format operator. ‘bar: %s’ % ‘tada’ results in the string ‘bar: tada’

[‘tag\_Environment\_%s’ % args.environment] results in a list containing one element: a string that begins with ‘tag\_Environment\_’ followed by whatever args.environment contains.

Cheers,  
Paul

---

<div class="post-metadata">

**Author:** ![Kevin\_Bullock](https://avatars.discourse-cdn.com/v4/letter/k/f1d935/32.png) [@Kevin\_Bullock](https://forum.ansible.com/u/Kevin_Bullock)\
**Post date:** [April 25, 2015, 2:58pm UTC](https://forum.ansible.com/t/what-does-this-mean-tag-environment-s-args-environment/18085/3 "2015-04-25T14:58:19Z")

</div>

That's how Python does string interpolation, in a similar style to C's sprintf(). [https://docs.python.org/2/library/stdtypes.html#string-formatting-operations](https://docs.python.org/2/library/stdtypes.html#string-formatting-operations)

pacem in terris / мир / शान्ति / ‎‫سَلاَم‬ / 平和  
Kevin R. Bullock

---

<div class="post-metadata">

**Author:** ![Paul\_Stivers](https://avatars.discourse-cdn.com/v4/letter/p/b9e5f3/32.png) [@Paul\_Stivers](https://forum.ansible.com/u/Paul_Stivers)\
**Post date:** [April 25, 2015, 5:23pm UTC](https://forum.ansible.com/t/what-does-this-mean-tag-environment-s-args-environment/18085/4 "2015-04-25T17:23:18Z")

</div>

Awsome! Without the print function I wasn’t thinking format. Nice, clear explanation. Thanks!

Paul
