Basic
hello.py
#!/bin/python
print "Hello World"
$ ./hello.py
Hello World
File
file.py
#!/bin/python
import os.path
if os.path.isfile("error.log"):
os.remove("error.log")
else:
print "Doesn't exist"
write.py
#!/bin/python
# overwrite
log = open('access.log', 'w')
log.write("ABCD\n")
log.close()
# append write
log = open('access2.log', 'a+')
log.write("ABCD\n")
log.close()
Recommended Posts