tao123 hkPython进阶_1读写文件

  #写文件

  str1=test

  #1、新建文件流

  write=open(123.txt,w)

  #write=file(123.txt,w)

  #2、写文件

  write.write(str1)

  #3、关闭文件流

  write.close()

  #读文件

  #1、新建文件流

  read=open(123.txt,r)

  #read=file(123.txt,r)

  #2、从文件流中读取内容

  str2=read.readline()

  #3、关闭文件流

  read.close()

  printstr2

相关链接:

·ShuoDaXueSheTuanShuiDiShiNiMeiHunHaoBa?tao

·JessicaTaotao图片