PYTHON文件操作
# 文件的操作 # 打开 # open(文件地址,操作形式) ''' w:写入 r:读取 b:二进制 a:追加 ''' fb=open("C:/Users/Administrator/Desktop/11.txt","r") #\需转译成\\,或改成/ # 读取全部 date = fb.read() # 读取行 line = fb.readline() # 文件的关闭 fb.close() # 文件的写入 aa="一起学python" fb2 = open("C:/Users/Administrator/Desktop/112.txt","w") fb2.write(aa) fb2.close() # w会替换掉以前的内容 bb="一起学好python" fb2 = open("C:/Users/Administrator/Desktop/112.txt","w") fb2.write(bb) fb2.close() # w会替换掉以前的内容 cc="一起学好python" fb2 = open("C:/Users/Administrator/Desktop/112.txt","a") fb2.write(cc) fb2.close()