gpt4 book ai didi

python - 不支持的操作 :not writeable python

转载 作者:IT老高 更新时间:2023-10-28 20:50:13 25 4
gpt4 key购买 nike

电子邮件验证

#Email validator
import re


def is_email():
email=input("Enter your email")
pattern = '[\.\w]{1,}[@]\w+[.]\w+'
file = open('ValidEmails.txt','r')
if re.match(pattern, email):
file.write(email)

我想知道为什么我的数据不会写入磁盘。 Python说不支持我的操作。

is_email
file.write(email)
io.UnsupportedOperation: not writable

最佳答案

您以只读方式打开变量"file",然后尝试写入:

file = open('ValidEmails.txt','r')

改为使用 'w' 标志。

file = open('ValidEmails.txt','w')
...
file.write(email)

关于python - 不支持的操作 :not writeable python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27278755/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com