List

Mike C. Fletcher mcfletch at rogers.com
Mon Jun 3 18:38:41 CEST 2002


Okay, this is pretty basic stuff, I'll just go over it quickly and refer 
you to http://www.python.org/doc/Newbies.html which has introductory 
documentation for Python.  You'll particularly want to work on 
understanding the list as a data type and the manipulations you can use 
when working with it.

Imagine you have a list of elements returned by the function "into" 
(from the previous message):

pageData = [['p1','p2','p3'],['p4','p5','p6'],['p7','p8','p9'],['p10']]

You generate this list when the user requests the page, and look at the 
query value in the CGI environment to determine which page of results 
the user wants to retrieve:

	requestedPage = '2'

Now, you want requestedPage to show up as an integer index into your 
list of pageData, that is, it tells you what element in the compound 
list pageData should be used for generating the page.

	requestedPage = int(requestedPage)

(You'd want to do some error-checking there, making sure it really is an 
integer, catching a ValueError will work).

Now, to get the values for the particular page, you index into the 
pageData list using your new index:

	pageData[ requestedPage ]

Again, you want to do error checking catching an IndexError works there.

If you want to know the total number of pages, it's:

	len( pageData )

You then go about generating your page, being sure to enable/disable the 
forward (requestedPage-1)/backward (requestedPage+1) links depending on 
whether the user is on the first/last page (BTW: you can offer links to 
"first" and "last" on every page just by using 0 (first) and -1 (last) 
as the link indices).

Note: if there are no results at all, even 0 won't work as an index, 
you'll need to catch that condition and generate a "no results" page.

Hope this helps,
Mike

Gold Fish wrote:
...
> Sorry for the very stupid question but i still don't get my goal, that's is 
> using Mike C. Fletcher method i will generate the list of elements again 
> and don't know what size it is. For example :
> [['p1','p2','p3'],['p4','p5','p6'],['p7','p8','p9'],['p10']]
> I want to seperate this list again in order to using them later .It look 
> like you go to the realestate agent website and find the list of property 
> then you just want to display 3 properties per pages. And you can go to 
> other pages which also contain 3 properties as well until the last pages 
> which has only 1 items. For example:
> Page 1: ['p1','p2','p3']
> Page 2: ['p4','p5','p6']
> Page 3: ['p7','p8','p9']
> Page 4: ['p10']
> I didn't sleep well due to this problem Can any help me.
> 
_______________________________________
   Mike C. Fletcher
   http://members.rogers.com/mcfletch/







More information about the Python-list mailing list