xxxxxxxxxx
with open("foo.txt", "w") as foofile:
foofile.write("This is the contents of foo")
# open it back up again and verify what's in there
with open("foo.txt") as foofile:
print(foofile.read())
# -> This is the contents of foo
# now open it and again and write to it
with open("foo.txt", "w") as foofile:
foofile.write("Foo has been overwritten!")
# open it yet again and see what it says
with open("foo.txt") as foofile:
print(foofile.read())
# -> Foo has been overwritten!
xxxxxxxxxx
pythonCopywith open('myFolder/myfile.txt', "r") as myfile:
data = myfilef.read()
with open('myFolder/myfile.txt', "w") as myfile:
myfile.write(newData)