Py学习  »  Python

使用python在文件中写入数据

pio • 7 年前 • 1978 次点击  

我是编程新手。刚买了本书给初学者 Python . 里面有密码:

name = input("name")
email = input("whats ure email:) 
favoriteband = input("ure fav band") 
outputString = name + "|" email + "|" + favoriteband 
fileName = name + ".txt"
file = open(fileName, "wb") 
file.write (outputString) 
print (outputString , " saved in ", fileName) 
file.close ()

根据这本书,这很好,但我犯了个错误:

TypeError: a bytes-like object is required, not 'str'

我不知道怎么解决,书也没有解释。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/43559
文章 [ 2 ]  |  最新文章 7 年前