python基础操作

1. 按行读取文件

def readNode(filename):
   resultList = []
   with open(filename, 'r') as f:
       while True:
           line = f.readline() # string
           if not line:
               break
           if line[0] == '#':
               pass
           else:
               pageNode = line.split()
               resultList.append(pageNode)
   return resultList
posted @ 2021-04-16 17:41  linux_txl  阅读(237)  评论(0)    收藏  举报