How to empty an array - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32) +--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26) +--- Thread: How to empty an array (/showthread.php?tid=8298) |
- d.i.z - 2004-12-17 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') - d.i.z - 2004-12-17 ok, now i know: Quote:for i in range(0, len(myarray)): i 'borrowed' it from gametrailers script and sorry for posting in wrong forum (now corrected). - Asteron - 2004-12-17 (d.i.z @ dec. 16 2004,23:44 Wrote:how could i empty the array which is already filled with data?i think myarray[:] = [] which is equivalent to myarray[0:len(myarray) - 1] = [] explicitly deletes every element. - Kaer - 2004-12-17 (d.i.z @ dec. 17 2004,00:55 Wrote:ok, now i know: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 what about myarray=[] ? or del myarray - Asteron - 2004-12-17 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. - d.i.z - 2004-12-19 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. |