# Access ansible list in python script.

**URL:** <https://forum.ansible.com/t/access-ansible-list-in-python-script/19980>\
**Category:** Ansible Project\
**Created:** [December 10, 2015, 6:30am UTC](https://forum.ansible.com/t/access-ansible-list-in-python-script/19980 "2015-12-10T06:30:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anoop.kolari](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anoop.kolari](https://forum.ansible.com/u/anoop.kolari)\
**Post date:** [December 10, 2015, 6:30am UTC](https://forum.ansible.com/t/access-ansible-list-in-python-script/19980/1 "2015-12-10T06:30:48Z")

</div>

Hi,

I’m calling a python script by passing an ansible list as an argument.

command: “python /home/vagrant/setup/configs/update\_installed\_app.py [‘django-allauth’, ‘test’]”

But when i print this list in my python script its printing with misplaced quotes, so i couldnt process it with python.

[‘[django-allauth,’, ‘test]’]

“rc”: 0,  
“start”: “2015-12-10 06:22:12.327672”,  
“stderr”: “”,  
“stdout”: “[‘[django-allauth,’, ‘test]’]”,  
“stdout\_lines”: [  
“[‘[django-allauth,’, ‘test]’]”

Could someone please help me out here.

---

<div class="post-metadata">

**Author:** ![Mike\_Biancaniello](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Mike\_Biancaniello](https://forum.ansible.com/u/Mike_Biancaniello)\
**Post date:** [December 10, 2015, 4:08pm UTC](https://forum.ansible.com/t/access-ansible-list-in-python-script/19980/2 "2015-12-10T16:08:54Z")

</div>

Instead of passing a python list, can you pass a json string? Then, inside the py script, just use json.loads().

---

<div class="post-metadata">

**Author:** ![anoop.kolari](https://avatars.discourse-cdn.com/v4/letter/a/59ef9b/32.png) [@anoop.kolari](https://forum.ansible.com/u/anoop.kolari)\
**Post date:** [December 10, 2015, 5:53pm UTC](https://forum.ansible.com/t/access-ansible-list-in-python-script/19980/3 "2015-12-10T17:53:55Z")

</div>

Hi Mike,

Thank you for your response.

I resolved this by following steps.

1. I quoted the arguments passed with the command like python /home/vagrant/setup/configs/update\_installed\_app.py “**[‘django-allauth’, ‘test’]**”
2. In python script I can access it as a string. Then using python ‘ast’ module i’m converted it into python list.
