Have you tried request.session['prod'][-7:] ?

If that doesn't work, try list(request.session['prod'])[-7:]

Todd

On Nov 20, 2007 10:52 PM, Greg <[EMAIL PROTECTED]> wrote:
>
> Hello,
> I have a session variable.  Whenever anybody adds a product to this
> session variable it gets stored like so:
>
> request.session['prod'].append(b)
>
> This can make my session variable look like this:
>
> [<Style: a>, <Style: b>, <Style: c>, <Style: d>]
>
> //////////////
>
> I want to show the last 7 elements in my list,  Occassionally my list
> will only contain less than 7 elements...like above.  So in this case
> only 4 elements will be shown.  However, I'm getting errors with how I
> currently have it setup:
>
> request.session['prod'][len(request.session['prod']) -
> 6:len(request.session['prod'])]
>
> It doesn't work correctly when I have less than 7 elements in the
> list.  I guess it's because I have
>
> 'len(request.session['prod']) - 6'
>
> ///////////////
>
> Does anybody know how I can show the last 7 elements in my list, and
> if my list has less than 7 elements then it shows all of the elements?
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to