View Full Version : How to empty an array
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')
ok, now i know:
for i in range(0, len(myarray)):
myarray.pop()
i 'borrowed' it from gametrailers script :)
and sorry for posting in wrong forum (now corrected).
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.
ok, now i know:
for i in range(0, len(myarray)):
myarray.pop()
i 'borrowed' it from gametrailers script :)
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
solexalex
2004-12-17, 16:17
what about
myarray=[] ?
or
del myarray
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.
forgot to say thanks ;)
thanks asteron, it works well and seems to be clearer than kaer's solution (but thanks kaer too for the initial idea :))
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.