|
|
Question : write to file
|
|
hi i would like to know how do you write to a file but not overwriting it completely
eg: testfile james:1111
i wish to write it so it becomes james:4444 but it keeps overwriting the whole file
for line in open("testfile", "w").readlines(): list = line.strip().split(':')
newinput = raw_input("Enter number") list[1] = newinput
if (newinput == list[1]) print "success"
any help please ? thanks
|
Answer : write to file
|
|
If you use an open mode of "r+", you can update the file. Even with that, I don't think the code you showed will do what you specified, though.
|
|
|
|
|