我做了一些编辑(右引号和一个丢失的
+
):
name = input("name:")
email = input("whats ure email:")
favoriteband = input("ure fav band:")
outputString = name + " | " + email + " | " + favoriteband
fileName = name + ".txt"
file = open(fileName, "w") #opened in write mode but not in binary
file.write (outputString)
print (outputString , " saved in ", fileName)
file.close()
您之所以会遇到这个错误,是因为您是以二进制模式编写的,因此
b
在里面
wb
对于
file = open(fileName, "wb")
请改为:
file = open(fileName, "w")