# Do import statements need to be at the bottom in modules?

**URL:** <https://forum.ansible.com/t/do-import-statements-need-to-be-at-the-bottom-in-modules/16460>\
**Category:** Ansible Developer\
**Created:** [October 8, 2014, 1:36am UTC](https://forum.ansible.com/t/do-import-statements-need-to-be-at-the-bottom-in-modules/16460 "2014-10-08T01:36:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lorin\_Hochstein](https://avatars.discourse-cdn.com/v4/letter/l/5f9b8f/32.png) [@Lorin\_Hochstein](https://forum.ansible.com/u/Lorin_Hochstein)\
**Post date:** [October 8, 2014, 1:36am UTC](https://forum.ansible.com/t/do-import-statements-need-to-be-at-the-bottom-in-modules/16460/1 "2014-10-08T01:36:28Z")

</div>

I’ve noticed that all of the Ansible modules have their import statements near the bottom of the file instead of the top:

from ansible.module\_utils.basic import \*

If I’m writing a new module, do I need to put the import near the bottom? Or is it safe to put it near the top like in a conventional Python script?

Lorin

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [October 8, 2014, 12:47pm UTC](https://forum.ansible.com/t/do-import-statements-need-to-be-at-the-bottom-in-modules/16460/2 "2014-10-08T12:47:43Z")

</div>

Hi Lorin,

The imports are at the bottom because behind the scenes they are really doing code-insertion so Ansible can ship things without installing other files to the remotes.

More specifically, putting them at the bottom - because of this - does not upset the line numbers when the code is inserted, so any tracebacks have accurate, rather than shifted, line numbers, should they occur in the module.
