【发布时间】:2015-11-24 06:03:45
【问题描述】:
import os, sys
pandaFile = open("panda.txt", "w")
pandaRead = pandaFile.read()
if "NOON" in pandaRead:
print("Enter a noon:")
noon = input()
str.replace("NOON",noon)
if "ADJECTIVE" in pandaRead:
print("Enter an adjective:")
adjective = input()
str.replace("ADJECTIVE", adjective)
if "VERB" in pandaRead:
print("Enter and verb:")
verb = input()
str.replace("VERB",verb)
newcontent = open("panda.txt","w")
我的目标是打开文件“Panda.txt”文件。如果有ADVERB、VERB或NOON,用用户输入替换这些字符串。并重写“panda.txt”文件.
我的错误代码是:
pandaRead = pandaFile.read()
io.UnsupportedOperation: not readable
我在 Windows Vista Home 版本上使用带有 Python 3.4 的 Sublime text 2。
【问题讨论】:
-
那么您的实际问题是什么?
-
你的代码哪里出错了?
-
我建议你应该做一些关于文件输入输出和正则表达式的教程
-
它不起作用。我有一条错误消息 pandaRead = pandaFile.read() io.UnsupportedOperation: not readable。谢谢
-
将第 2 行替换为:
pandaFile = open("panda.txt", "r")以读取模式打开文件而不是写入
标签: python string python-3.x sys