weidagang2046的專欄

          物格而后知致
          隨筆 - 8, 文章 - 409, 評論 - 101, 引用 - 0
          數據加載中……

          怎樣把一個二維數組寫入文件

          發信人: ilovecpp (cpp), 信區: Python
          標  題: Re: 怎樣把一個二維數組寫入文件?
          發信站: 水木社區 (Tue Jan 17 23:39:50 2006), 站內

          【 在 petre (petre) 的大作中提到: 】
          : 比如
          : A=[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
          : 寫入文件后文件內容是
          : 1 2 3 4
          : 5 6 7 8
          : 9 10 11 12
          : 13 14 15 16
          : 就是不能帶"[ ]"
          : 每行占一行
          : 急著用,不熟悉python
          : //bow

          print >>open('a.txt', 'w'), '\n'.join([' '.join(map(str, i)) for i in A])

          posted on 2006-01-19 15:48 weidagang2046 閱讀(4878) 評論(1)  編輯  收藏 所屬分類: Python

          評論

          # re: 怎樣把一個二維數組寫入文件  回復  更多評論   

          map(...)
          map(function, sequence[, sequence, ...]) -> list

          Return a list of the results of applying the function to the items of
          the argument sequence(s). If more than one sequence is given, the
          function is called with an argument list consisting of the corresponding
          item of each sequence, substituting None for missing values when not all
          sequences have the same length. If the function is None, return a list of
          the items of the sequence (or a list of tuples if more than one sequence).
          2006-01-19 15:49 | weidagang2046

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 宣恩县| 凤山县| 金阳县| 肃南| 弥渡县| 北海市| 通道| 高唐县| 河北省| 延吉市| 永川市| 通州区| 长治市| 永新县| 汤原县| 新津县| 新宁县| 红原县| 洪江市| 乐陵市| 湖南省| 上栗县| 和静县| 新蔡县| 逊克县| 关岭| 绵竹市| 玉田县| 通海县| 霍林郭勒市| 丹棱县| 抚顺县| 甘洛县| 平谷区| 徐汇区| 古田县| 永城市| 枣庄市| 正阳县| 凤阳县| 凌云县|