title: [Python]Array function called in other function
body: <p>I've tried to create a function that generated 3 variables for my arrays so I can call it in any further function I will create.</p>
  
  <p>The 1st code was:</p>
  
  <pre><code>details = open('a.txt').readlines()
  
  for x in details:
  
      host   = x.split()[0]   
  
      user   = x.split()[1]
  
      passwd = x.split()[2]
  
      print host + " --&gt; " + user + " --&gt; " + passwd
  </code></pre>
  
  <p>So the output is:</p>
  
  <p>python b.py</p>
  
  <p>192.168.1.1 --> user --> password</p>
  
  <p>192.168.1.2 --> user --> password</p>
  
  <p>Now, if I create multiple functions I have to use the same code as many functions as I create right? Then I decided to create the function to load those details from a.txt</p>
  
  <p>Now, this is what happens:</p>
  
  <pre><code>def load_data():
  
  global details,host,user,passwd
  
  details = open('a.txt').readlines()
  host   = [x.split()[0] for x in details]
  user   = [x.split()[1] for x in details]
  passwd = [x.split()[2] for x in details] 
  </code></pre>
  
  <p>Great, now let's call load_data in another function and execute the actual function:</p>
  
  <pre><code>def execute():
  
  load_data()
  
  print host
  </code></pre>
  
  <p>Output:</p>
  
  <p>python b.py</p>
  
  <p>['192.168.1.1', '192.168.1.2']</p>
  
  <p>I don't understand why the foreach (as in PHP) is not working if I call it in another function and execute it?</p>
  
  <p>The output must be:</p>
  
  <p>192.168.1.1</p>
  
  <p>192.168.1.2</p>
  
  <p>Can please somebody help me? (I'm a beginner in Python, so please take it slow.)</p>
  
  <p>Thank you!</p>