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

  • From: "Littlefield, Tyler" <tyler@xxxxxxxxxxxxx>
  • To: program-l@xxxxxxxxxxxxx
  • Date: Mon, 01 Oct 2012 16:34:28 -0600

Al:
You could just have a class that handles this data for you.
def __init__(self, date, opening, high, low, closing,
volume):
...
then it could store those lists (since I assume each list is a history of data) so you can get back correllations.
HTH,
On 10/1/2012 1:24 PM, Homme, James wrote:
Hi,
Please know that this is an uneducated answer. I'm thinking that you could have 
something like an ini style file that would have a section in it for each web 
site and then use the configparser module to handle the data. See 
http://docs.python.org/library/configparser.html. You use this to load up 
Python dictionaries and get at their keys.

Thanks.

Jim


-----Original Message-----
From: program-l-bounce@xxxxxxxxxxxxx [mailto:program-l-bounce@xxxxxxxxxxxxx] On 
Behalf Of Al Puzzuoli
Sent: Monday, October 01, 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

________________________________

This e-mail and any attachments to it are confidential and are intended solely 
for use of the individual or entity to whom they are addressed. If you have 
received this e-mail in error, please notify the sender immediately and then 
delete it. If you are not the intended recipient, you must not keep, use, 
disclose, copy or distribute this e-mail without the author's prior permission. 
The views expressed in this e-mail message do not necessarily represent the 
views of Highmark Inc., its subsidiaries, or affiliates.
Nï^jïïbïï%ïï(ïï^ïiïv&ïz\ïïYhï)ï)äïïïkï
ÚZÞçïïzXïïï+ïËïï-éï&ï!ïaïïbïGhzïïÂïïïïïjgïïïïïkï
ÚZÞçïïzXïïï+ïïÝ{ay+ïïï-ï)Þ*^ï{.nï+ïïïïï-ïïïï\ïiïïï,ïïZïïjØïjyïbrJ'ïïïgïïï^ï'ïZ0ïx%ïy&j)mïïèïïïïïï-~ïïï+-ïïïïïyï}ïïïÇuïïïÆzï)ïï+jikzïïïïïyïbïï(ï
"ïay+ïïï-faq=


--
Take care,
Ty
http://tds-solutions.net
The aspen project: a barebones light-weight mud engine:
http://code.google.com/p/aspenmud
He that will not reason is a bigot; he that cannot reason is a fool; he that 
dares not reason is a slave.

Other related posts: