title: How to import and get variables from another python file?
body: <p>The main file is aaa.py, code as below:</p>
  
  <pre><code>import os,time
  from get_newest_folder import *
  
  def main_test():
      print(newest_folder)
      print(path)
  
  if __name__ == '__main__':
      get_n_folder()
      main_test()
  </code></pre>
  
  <p>The another file is get_newest_folder.py, code as below:</p>
  
  <pre><code>import os
  
  def get_n_folder():
  
      path = 'D:\\Test'    
      os.chdir(path)
      files = sorted(os.listdir(os.getcwd()), key=os.path.getmtime)
  
      newest_folder = files[-1]
      return (path, newest_folder)
  
  if __name__ == '__main__':
      get_n_folder()
  </code></pre>
  
  <p>I'm trying to use variable "path" and "newest_folder" from get_newest_folder.py in aaa.py, so I import "get_newest_folder". But I can't get(print) the 2 variables in aaa.py. It displays the error message as below when I run aaa.py:</p>
  
  <blockquote>
    <p>NameError: name 'newest_folder' is not defined</p>
  </blockquote>
  
  <p>Does anyone can correct my code or give me some suggestion? 
  Many thanks.</p>