随手记:Python读取文件使用with open as 是否需要close?
在使用Python读取文件预处理时,常常会遇到这样的语句: with open(target_path, 'r') as f: for row in csv.reader(open(source_path, 'r')): # print(row[0], row[1]) # ...... f.close() 还有一种写法: G = nx.Graph() datafile = open(filepath) lines = datafile.readlines(line) length = len(lines)...