czwartek, 28 listopada 2013

file truncate python

#!/usr/bin/python
from sys import argv
import os

script, filename = argv

check = os.stat(filename)[6]==0

if check == False:
    print "the file %r. " %filename, "will be erased"
    print "press enter to continue.."
    raw_input("?")
    print "opening the file: ..%r" %filename
    target = open(filename, 'w')
    print "erasing..."
    target.truncate()

    print "closing ... "
    target.close()
else:
    print "file is empty"


Brak komentarzy:

Prześlij komentarz