How to empty a list after a loop iteration

24 views
Skip to first unread message

Maurice Waka

unread,
May 7, 2018, 6:06:42 AM5/7/18
to web2py-users
I have done this in python 2.7 idle and it works well.
l = []
def one():
    l
.append('1one')

def two():
    l
.append(None)

def three():
    l
.append('three')

def four():
    l
.append(None)
def empty():
       
del l[:]

def Filter():                      
    four
()
    two
()
    one
()
    three
()
   
for item in l:
       
try:
           
print [x for x in l if x is not '' and x is not None'][0]
            pass
        except:
            pass    
    empty()
         
if __name__=='
__main__':      
    Filter()

My aim is to return values in the list 'l' to the view page. After which, the list is to remain empty. When the list is not empty and I refresh the page, new items keep adding to the 'l' in addition to the previous ones.
i don't know why it works in idle and not in web2py.

Kind regards

pbreit

unread,
May 7, 2018, 12:54:52 PM5/7/18
to web2py-users
I'm not sure that's going to work since the list will not persist between page views.

Do you want to do something like this using "sessions"?

Maurice Waka

unread,
May 7, 2018, 1:45:42 PM5/7/18
to web...@googlegroups.com
Actually I found out that I can empty the list before new insertion / append.


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/bKgHyUoDNXI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages