title: Issues returning python parameter to main function
body: <p>problem: Im trying to extract values out of a mysql search to use later within the code.
  I have setup a mysql function (connector_mysql) that i use to connect/run the mysql commands.
  The problem i'm having is returning these values back out of the mysql function to the rest of the code.
  There are two scenarios that i've tried which i think should work but dont when run.
  full code sample below...
  1. In the mysql function result acts like a dictionary if - using just..</p>
  
  <pre><code>result = cursor.fetchone(variable1, variable2, variable3)
  return result
  </code></pre>
  
  <p>AND in the main function</p>
  
  <pre><code>    result1 = connector_mysql(subSerialNum, ldev, today_date)
      print(result1)
  </code></pre>
  
  <p>This appears to work and when printing result1 i get a dictionary looking output:</p>
  
  <pre><code>    {'ldev_cap': '0938376656', 'ldev_usedcap': '90937763873'}
  </code></pre>
  
  <p>HOWEVER...
  I cant then use dictionary methods to get or separate the values out.. eg</p>
  
  <pre><code>used_capacity = result1['ldev_cap']
  </code></pre>
  
  <p>which i would have expected that now 'used_capacity' to represent or equal 0938376656.
  Instead i get an error about the object is not able to be subscripted...?
  Error below:</p>
  
  <pre><code>  File "/Users/graham/PycharmProjects/VmExtrat/VmExtract.py", line 160, in openRead
  used_capacity = result1['ldev_cap']
  </code></pre>
  
  <p>TypeError: 'NoneType' object is not subscriptable</p>
  
  <ol start="2">
  <li><p>In the mysql function the result acts like a dictionary if I manipulate it and try and return multiple values with the tuple concept - using..</p>
  
  <pre><code>cursor.execute(sql_query, {'serial': subSerialNum, 'lun': ldev, 'todayD': today_date})
  result = cursor.fetchone()
  while result:
      ldev_cap = result['ldev_cap']
      ldev_usdcap = result['ldev_usdcap']
      return ldev_cap, ldev_usdcap
  </code></pre></li>
  </ol>
  
  <p>Here, result acts like a dictionary and i'm able to assign a parameter to the key like:</p>
  
  <pre><code>ldev_cap = result['ldev_cap']
  </code></pre>
  
  <p>and if you print ldev_cap you get the correct figure...
  If I return one figure, the main function line of:</p>
  
  <pre><code>result1 = connector_mysql(subSerialNum, ldev, today_date)
  </code></pre>
  
  <p>it Works....
  HOWEVER...
  When then trying to return multiple parameters from the mysql function by doing</p>
  
  <pre><code>return ldev_cap, ldev_usdcap
  </code></pre>
  
  <p>and in the main function:</p>
  
  <pre><code>capacity, usd_capacity = connector_mysql(subSerialNum, ldev, today_date)
  </code></pre>
  
  <p>I get errors again</p>
  
  <pre><code>  File "/Users/graham/PycharmProjects/VmExtrat/VmExtract.py", line 156, in openRead
  capacity, usd_capacity = connector_mysql(subSerialNum, ldev, today_date)
  </code></pre>
  
  <p>TypeError: 'NoneType' object is not iterable</p>
  
  <p>I think i'm doing the right thing with the dictionary and the tuple but i'm obviously missing something or not doing it correctly, as i need to do this with 4-5 paramaters per sql query,
  I didn't want to do multiple querys for the same thing to get the individual paramaters out.</p>
  
  <p>Any help or suggestions would be greatly welcomed...
  full code below.</p>
  
  <p>main code:</p>
  
  <pre><code>capacity, usd_capacity = connector_mysql(subSerialNum, ldev, today_date)
  print(capacity)
  print(usd_capacity)
  
  def connector_mysql(subSerialNum, ldev, today_date):
  
      import pymysql.cursors
  
      db_server = 'localhost'
      db_name = 'CBDB'
      db_pass = 'secure_password'
      db_user = 'user1'
  
      sql_query = (
          "SELECT ldev_cap, ldev_usdcap FROM Ldevs WHERE sub_serial=%(serial)s "
          "and ldev_id=%(lun)s and data_date=%(todayD)s")
  
      connection = pymysql.connect(host=db_server,
                                   user=db_user,
                                   password=db_pass,
                                   db=db_name,
                                   cursorclass=pymysql.cursors.DictCursor)
  
      try:
          with connection.cursor() as cursor:
              cursor.execute(sql_query, {'serial': subSerialNum, 'lun': ldev, 'todayD': today_date})
              result = cursor.fetchone()
              #return result          #used for returning dict
  
              while result:
                  ldev_cap = result['ldev_cap']
                  ldev_usdcap = result['ldev_usdcap']
  
                  print(result)
                  return ldev_cap, ldev_usdcap
  
      finally:
          connection.close()
  </code></pre>