Hi all,
my problem is delete a line in a text file.
the file contain -n line with user, userCode.
i want to replace the line with user is egual at user, and/or insert new line but delete the line like user.
i'm sorry for my english :D
if user exist delete a line of the user and insert new line.
if not exist insert new line.
possibility to delete a line.
please :D
my problem is delete a line in a text file.
the file contain -n line with user, userCode.
i want to replace the line with user is egual at user, and/or insert new line but delete the line like user.
i'm sorry for my english :D
if user exist delete a line of the user and insert new line.
if not exist insert new line.
possibility to delete a line.
please :D
Code:
user="myname"
userCode="1987987981"
f = open('userCodes.txt', 'r+')
for line in f:
if user in line:
print 'prima ' + str(line)
line = line.replace(line, user + ',' + str(userCode) + '\n')
f.write('\n' +str(line))
print 'dopo ' + str (line)
Comment