方法可以有三个,但其实是一个方法,因为不同的方法都是文件存储的方法,文件修改就只有一个方法: 将文件导入list后,重新写入文件(另一个文件或者当前文件) 1.当前文件读取后,list修改内容,写入另一个新建文件 f = open("D:\data\k1.TXT","r") ff= open ("D:\data\\new\k1.TXT","w") new=[] for line in f: new.append(line) n
#! /bin/python filename='setup.ini' lines=[] with open(filename,'r') as f: lines=f.readlines() lines[1]='namespace = qmone-33c49600-4c22-486d-a397-e4f02bcdcf18' + '\n' lines[2]='interface = mon-33c4960d-0c' + '\n' with open(filename,'w') as f: for da
os.chmod()方法 此方法通过数值模式更新路径或文件权限.该模式可采取下列值或按位或运算组合之一: stat.S_ISUID: Set user ID on execution. stat.S_ISGID: Set group ID on execution. stat.S_ENFMT: Record locking enforced. stat.S_ISVTX: Save text image after execution. stat.S_IREAD: Read by owner. s
处理数据时候,需要得到数据所在和行号,使用enumerate时便捷的方法: file = open('file.txt','r') for (num,value) in enumerate(file): print "line num is: ",num,"content:",value file.close()