当前位置:首页 > Python教程 > python技巧

python读取文件内容方法

1) readline 每次读一行,返回序列

2) readlines 一次全部读出,返回序列

3) numpy 的genfromtxt,返回为np的矩阵格式

            import
             numpy as np
      f=file(sample.txt,r)
      ll=np.genfromtxt(sample.txt,dtype=None)
      lline=f.readlines()
      
      print ll,lline
      for line in lline
          print line
          singleline=f.readline()    
          source=line.rstrip()# 去除换行符
          name = source.split()[0]
          ra = source.split()[1]
          dec = source.split()[2]
          ........

 

原文:http://www.cnblogs.com/heshangaichirou/p/5104286.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐