How do I kill an empty file ??
Fredrik Lundh
fredrik at effbot.org
Wed Jan 24 02:54:27 EST 2001
"bowman" wrote:
> os.stat(file) will yeild a tuple including st_size. the stat module defines
> indices, so
>
> if os.stat(file)[ST_SIZE] == 0:
> pass
>
> or somesuch
os.path.getsize does the same thing, but is a bit
easier to use:
os.path.getsize(file)
if not os.path.getsize(file):
pass
...but in this case, it might be easier to load the file
and just don't do anything if it's empty:
for file in files:
data = open(file).readlines()
if not data:
continue
... prepare to process file ...
for line in data:
... process line in file ...
Cheers /F
More information about the Python-list
mailing list