不支持的操作:不可写的python [英] Unsupported operation :not writeable python

查看:67
本文介绍了不支持的操作:不可写的python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

电子邮件验证

#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 说不支持我的操作.

I am wondering why my data wont write to the disk. Python says that my operation is not supported.

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

推荐答案

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

You open the variable "file" as a read only then attempt to write to it:

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

改为使用w"标志.

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

这篇关于不支持的操作:不可写的python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆