title: in python, how to make main args global
body: <p>I want to access the args values in a class function in python.<br>
  For example, I wrote a sample test program below.  </p>
  
  <pre><code>#!/usr/bin/env python
  
  import argparse
  
  class Weather(object):
      def __init__(self):
          self.value = 0.0
      def run(self):
          print('in weather.run')
          if (args.sunny == True):
              print('It\'s Sunny')
          else:
              print('It\'s Not Sunny')
  
  def main():
      argparser = argparse.ArgumentParser(
          description=__doc__)
      argparser.add_argument(
          '--sunny', action='store_true', dest='sunny', help='set if you want sunny weather')
      args = argparser.parse_args()
  
      print('args.sunny = ', args.sunny)
  
      weather = Weather()
  
  
      weather.run()
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>When I run it(./test.py), I get errors below.  </p>
  
  <pre><code>('args.sunny = ', False)
  in weather.run
  Traceback (most recent call last):
    File "./test.py", line 30, in &lt;module&gt;
      main()
    File "./test.py", line 27, in main
      weather.run()
    File "./test.py", line 10, in run
      if (args.sunny == True):
  NameError: global name 'args' is not defined
  </code></pre>
  
  <p>I tried putting 'global args' in the Weather.run function but got the same error. What is the correct method?</p>