How to empty an array
#1
how could i empty the array which is already filled with data?

i tried everything, splice, clear, assigning some empty data and still nothing.

the array is defined globally, for example myarray = []

and then filled with data with myarray.append('something')
Reply
#2
ok, now i know:
Quote:for i in range(0, len(myarray)):
myarray.pop()

i 'borrowed' it from gametrailers script Smile

and sorry for posting in wrong forum (now corrected).
Reply
#3
(d.i.z @ dec. 16 2004,23:44 Wrote:how could i empty the array which is already filled with data?

i tried everything, splice, clear, assigning some empty data and still nothing.

the array is defined globally, for example myarray = []

and then filled with data with myarray.append('something')
i think
myarray[:] = []

which is equivalent to

myarray[0:len(myarray) - 1] = []

explicitly deletes every element.
Reply
#4
(d.i.z @ dec. 17 2004,00:55 Wrote:ok, now i know:
Quote:for i in range(0, len(myarray)):
myarray.pop()

i 'borrowed' it from gametrailers script Smile

and sorry for posting in wrong forum (now corrected).
haha im the gametrailers author and was abt to post the same thing. i cant find a better method to delete though, will try asteron method nxt time
Reply
#5
what about
myarray=[] ?

or

del myarray
Reply
#6
i think that those two dont free up what the list refers to


from http://rgruet.free.fr/pqr2.3.html#list

s.pop() is the same as x = s[-1]; del s[-1]; return x
where s[-1] = s[len(s)-1]

also s[:] = [] is the same as s[0:len(s)-1] = []
which is the same as del s[0:len(s)-1]

i really would wish there was a nice clear() though.
Reply
#7
forgot to say thanks Wink

thanks asteron, it works well and seems to be clearer than kaer's solution (but thanks kaer too for the initial idea Smile)

and here is my small script: http://prgk.xtina.pl/xbmc/gamescommercials.py
this is for browsing majkel's game commercials page (http://www.majkel.mds.pl/html/reklama/)

as soon as i implement few more ideas i still have left, i will upload it to xbmc scripts page.
Reply

Logout Mark Read Team Forum Stats Members Help
How to empty an array0