title: Function Help for Json object
body: <p>I am new to python and programing.  I wrote this original script to handle some Facebook data from the open graph.</p>
  
  <p>It works and does produce the .csv I want.</p>
  
  <pre><code>def main():
      ts = FacebookSearch()
      data = ts.search('appliance')
      js = json.loads(data)
  
      messages = ([msg['created_time'], msg.get('message', 'Key "message" is not present.').replace('\n', '').replace(',', '').encode('utf8'),  msg['from']['id']] for msg in js.get('data', []))
  
      write_csv('fb_washerdryer.csv', messages, append=True)
  </code></pre>
  
  <p>Problems with the above code:</p>
  
  <p>1.) it is long and horrible looking
  2.) I want to shorten the total size of 'message' to 900 varchar</p>
  
  <p>In order to accomplish the above I broke messages into a function of its' own:</p>
  
  <pre><code>def main():
      ts = FacebookSearch()
      data = ts.search('appliance')
      js = json.loads(data)
  
  def extract_info(msg):
      created_time = msg['created_time']
      message = msg.get('message', 'Key "message" is not present.').replace('\n', '').replace(',', '').encode('utf8')
      user_id = msg['from']['id']
      return (created_time, message, user_id)
  
      messages = (extract_info(msg) for msg in js.get('data', []))
  
  
      write_csv('fb_washerdryer.csv', messages, append=True)
  </code></pre>
  
  <p>I don't get an error when I run this new code but I doesn't print anything either.  </p>
  
  <p>Any thoughts into what I did wrong for it not to print.  Since I don't have an error I am little stuck and havent gotten to my 2nd task of shortening the 'message' string</p>