tensor_zhang 2018-09-22 15:06 采纳率: 0%
浏览 1548

用‘w+’格式写文件之后,在进行读操作结果没有输出,也没有报错

代码如下
from sys import argv
script, filename = argv
print("we are going to erase %r"%(filename))
print("if you don't want that, hit ^c")
print("if you do want that, hit return")

input("?")

print("opening the file...")
target = open(filename, 'w+')

print("truncating the file")
target.truncate()

print("now i am going to ask you for three lines")

line1 = input("line 1: ")
line2 = input("line 2: ")
line3 = input("line 3: ")

print("i am going to write these to the file")

target.write(line1)
target.write("\n")
target.write(line2)
target.write("\n")
target.write(line3)
target.write("\n")

print("now this is your new file")
print(target.read())
#不知道为什么没有打出来,也没报错

print("and finally, we close it")
target.close()

图片说明

  • 写回答

3条回答 默认 最新

  • threenewbee 2018-09-22 18:01
    关注

    你的文件名和文件路径是什么,用绝对路径试试看。检查下对应目录的权限,或者用管理员模式运行

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器