# code questions

**URL:** <https://forum.ansible.com/t/code-questions/11301>\
**Category:** Ansible Project\
**Created:** [February 26, 2012, 12:02am UTC](https://forum.ansible.com/t/code-questions/11301 "2012-02-26T00:02:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seth\_Vidal](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@Seth\_Vidal](https://forum.ansible.com/u/Seth_Vidal)\
**Post date:** [February 26, 2012, 12:02am UTC](https://forum.ansible.com/t/code-questions/11301/1 "2012-02-26T00:02:28Z")

</div>

This is used a lot:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if host\_list is None:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host\_list = self.host\_list

curious - do you mean 'if nothing has been specified' or if the object  
is actually None?

Just trying to distinguish between an empty list or an empty string.

since:

> > foo =   
> > foo is None

False

> > foo = ''  
> > foo is None

False

If you're checking for specifically None there, then that's fine -  
otherwise we can just do: if not host\_list:

I couldn't tell from the context which was desired.

thanks

-sv

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [February 26, 2012, 12:45am UTC](https://forum.ansible.com/t/code-questions/11301/2 "2012-02-26T00:45:39Z")

</div>

It is intended to detects if no argument is passed in to the key value argument and then resets the value to the class default. This is because in a method you can’t default a key value argument to an attribute of the class, as it’s illegal to dereference self there.

–Michael
