python calling variables from another script into current script
<p>I'm trying to call a variable from another script into my current script but running into "variable not defined" issues.</p>

<p>botoGetTags.py</p>

<pre><code>20 def findLargestIP():
 21         for i in tagList:
 22                 #remove all the spacing in the tags
 23                 ec2Tags = i.strip()
 24                 #seperate any multiple tags
 25                 ec2SingleTag = ec2Tags.split(',')
 26                 #find the last octect of the ip address
 27                 fullIPTag = ec2SingleTag[1].split('.')
 28                 #remove the CIDR from ip to get the last octect
 29                 lastIPsTag = fullIPTag[3].split('/')
 30                 lastOctect = lastIPsTag[0]
 31                 ipList.append(lastOctect)
 32                 largestIP  = int(ipList[0])
 33                 for latestIP in ipList:
 34                         if int(latestIP) &gt; largestIP:
 35                                 largestIP = latestIP
 36         return largestIP
 37         #print largestIP
 38
 39 if __name__ == '__main__':
 40         getec2Tags()
 41         largestIP = findLargestIP()
 42         print largestIP
</code></pre>

<p>So this script ^ correctly returns the value of <code>largestIP</code> but in my other script </p>

<p>terraform.py</p>

<pre><code>  1 import botoGetTags
  8 largestIP = findLargestIP()
</code></pre>

<p>before I execute any of the functions in my script, terraTFgen.py, I get:</p>

<pre><code>Traceback (most recent call last):
  File "terraTFgen.py", line 8, in &lt;module&gt;
    largestIP = findLargestIP()
NameError: name 'findLargestIP' is not defined
</code></pre>

<p>I thought that if I import another script I could use those variables in my current script is there another step I should take?</p>

<p>Thanks</p>

<p>You imported the module, not the function. So you need to refer to the function via the module:</p>

<pre><code>import botoGetTags
largestIP = botoGetTags.findLargestIP()
</code></pre>

<p>Alternatively you could import the function directly:</p>

<pre><code>from botoGetTags import findLargestIP
largestIP = findLargestIP()
</code></pre>

python function import