weidagang2046的专栏

物格而后知致
随笔 - 8, 文章 - 409, 评论 - 57, 引用 - 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 阅读(567) 评论(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



标题  
姓名  
主页
验证码 *  
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
 
 
相关链接:
网站导航: