[program-l] Python, best way to return a bunch of data from a function?

  • From: Al Puzzuoli <alpuzz@xxxxxxxxx>
  • To: program-l@xxxxxxxxxxxxx
  • Date: Mon, 01 Oct 2012 11:23:14 -0400

Hi everyone,
For my current project, I'm envisioning having a number of different data collection functions. Currently, I'm working with Yahoo. I'm using Urllib to download a CSv file. I then zip the data into appropriate columns, convert it from tuples to lists. Next, I pop the header rows off my lists and convert them to floating point values. Right now, this code is running as part of my main program, but I ultimately want to modularize it and later add data collectors for other sources. So in the case of Yahoo, the above process does the job, but another source might offer the data in JSON format or whatever. Ultimately, how I parse the data should be transparent to the program. The important thing is that the main program gets back 6 lists, date, opening, high, low, closing, volume. The most obvious way to do this would seem to be to declare these list as global variables in my data collection functions, but I'm afraid that if I use global variables, I shall incur the wrath of the programming GODS and be afflicted forever after by vengeful gremlins from on high. So is this instance an acceptable use case for global variables? If not, what would be the best way to formulate a function that would do all the necessary parsing and processing, and then return all the data I need in a single pass?
Thanks,

Al

** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

Other related posts: