[英]edit file using by taking user input in python?
i want to edit email id and phone number by taking user input but i am unable to that through this what i am doing wrong in this code help. 我想通过接受用户输入来编辑电子邮件ID和电话号码,但是我无法通过此操作来解决此代码帮助中的错误。
file.txt file.txt的
Jon Snow 996452544 Jon@gmail
Robb 885546694 Robb@gmail
Robert 896756885 Robert@gmail
code 码
def editContact():
obj2 = open("address.txt","r")
output = []
old_email=raw_input("Enter old email address : ")
new_email=raw_input("Enter new email address : ")
s = re.sub(old_email, new_email, obj2)
obj1 = open("address.txt","w")
obj1.writelines(s)
I think the issue you are having is : 我认为您遇到的问题是:
s = re.sub(old_email, new_email, obj2)
obj2 here is a file obj, read the file using obj2.read() obj2这里是文件obj,请使用obj2.read()读取文件
then you will be able to replace. 那么您将可以更换。
abc=obj2.read()
s = re.sub(old_email, new_email, abc)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.