鱼C论坛

 找回密码
 立即注册
查看: 2333|回复: 18

[已解决]replace报错

[复制链接]
发表于 2020-5-16 22:53:04 | 显示全部楼层    本楼为最佳答案   
本帖最后由 hrp 于 2020-5-16 22:55 编辑
  1. f = open("D:\\filetxt2.txt", 'w')
  2. str1 = "Hello,World!"
  3. f.write(str1)
  4. f.close()
  5. f = open("D:\\filetxt2.txt", 'r+')
  6. content = f.read()
  7. if "World" in content:
  8.     content_new = content.replace("World", "Python")
  9.     # f = f_new
  10.     # content = f.read()
  11.     print(content_new)
  12. f.close()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-3 08:06

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表