title: Have a function or class to store local variables that are parsed from yaml file in Python
body: <p>I have a few lines of code that will open a yaml file and parse some values and store them in local variables in PYTHON.</p>
  
  <p><strong>config.yml:</strong></p>
  
  <pre><code>mysql:
    host: localhost
    database: myDatabase
    user: root
    password: root
  </code></pre>
  
  <p>and my code so far:</p>
  
  <pre><code>import yaml
  with open("config.yml", 'r') as ymlfile:
  cfg = yaml.load(ymlfile)
  
  host = cfg["mysql"]["host"]
  database = cfg["mysql"]["database"]
  user = cfg["mysql"]["user"]
  password = cfg["mysql"]["password"]
  </code></pre>
  
  <p><strong>I was wondering if there is a way I can store this in a neat function, and more importantly, call each variable from another function.</strong></p>
  
  <p>Something like:</p>
  
  <pre><code>def parse_config():
      &lt;code&gt; 
  
  def main():
      password = parse_config() 
  </code></pre>
  
  <p><strong>Also, would it be better to have this in a SEPERATE class?</strong></p>