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

  • From: "Corbett, James" <James.Corbett@xxxxxxxxxxxxx>
  • To: "'program-l@xxxxxxxxxxxxx'" <program-l@xxxxxxxxxxxxx>
  • Date: Mon, 1 Oct 2012 19:43:40 +0000

Hi:

I'm not a Python programmer but I play one on TV.

If Python allows you to create objects then you could pass around fully 
hydrated objects:

Public MyObject returnFunction() {
//do something with the object
Return myObject;
}

Jim 
-----Original Message-----
From: program-l-bounce@xxxxxxxxxxxxx [mailto:program-l-bounce@xxxxxxxxxxxxx] On 
Behalf Of Al Puzzuoli
Sent: October 1, 2012 11:23 AM
To: program-l@xxxxxxxxxxxxx
Subject: [program-l] Python, best way to return a bunch of data from a function?

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
** 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: