[Tutor] Importing a List from Module

Byron byron at christianfreebies.com
Sun Aug 28 06:25:36 CEST 2005

Tom Strickland wrote:
> In my "main" module I import "enterData" and try to read the first 
> element of "close" as follows:
>     import enterData
>     xy=enterData.close
>     print xy[0]   
> When I do this it prints out the entire "close" list, not just the first 
> term.

Hi Tom,

I would create a function in your module that returns the list.  Here's 
a quick, simplified example:

def returnList():
	newList = []
	newList += [123.45]
	newList += [529.59]
	newList += [259.92]
	return newList
aList = returnList()
print aList

Note the return statement...  This enables assignment, as you have done 
in "xy=enterData.returnList()"

Hope this helps,


More information about the Tutor mailing list