python數組遍歷三種實用方法

 >>> os.__file__.split('\') ['E:', 'Python', 'Python25', 'lib', 'os.pyc'] >>> os.path.split(os.__file__) ('E:\Python\Python25\lib', 'os.pyc') var myArr:Array = new Array("one", "two", "three"); var myStr:String = myArr.join(" and "); trace(myArr); // one,two,three trace(myStr); // one and two and three 1) 將每個id的屬性值插入數組,Aarry.join(",") 成字符串,保存到一個txt里,或者數據庫表裡。(txt首選) 1) python直接解析 split(",") 成數組,索引+1是文件名,值是數據庫id,讀取數據庫, 用enumerate函數,遍曆數組,生成xml。(首選) 在Python中,我們習慣這樣遍歷: for item in sequence: process(item) 這樣遍歷取不到item的序號i,所有就有了下面的遍歷方法: for index in range(len(sequence)): process(sequence[index]) 其實,如果你了解內置的enumerate函數,還可以這樣寫: for index, item in enumerate(sequence): process(index, item)