I have a python (v2.7.2 on OSX Lion) script that unzips an archive into a new folder, and then finds a csv within those files. It then attempts to open the CSV and read through it.
This was all working as expected, up to a point. The problem i have been running into is that, when executed as described above, at times the script perceives the file to be 0 length. But when I run the same code from the command line interpreter, it sees the file correctly. Can anyone help me understand what the reason for this might be?
Pseudo Code:
# unzip the archive, locating csvfile along the way...
statinfo = os.stat(unzip_dir + "/" + csvfile)
print statinfo
output from the above snippet:
posix.stat_result(st_mode=33188, st_ino=5318966, st_dev=234881026L, st_nlink=1, st_uid=0, st_gid=80, st_size=0, st_atime=1329963124, st_mtime=1329963124, st_ctime=1329963124)
(notice st_size=0!)
Now I go directly to the python command line and enter:
import os
statinfo = os.stat("/Users/Me/Testdir/test.csv")
print statinfo
Output from the above snippet:
posix.stat_result(st_mode=33188, st_ino=5318966, st_dev=234881026L, st_nlink=1, st_uid=0, st_gid=80, st_size=290, st_atime=1329963124, st_mtime=1329963124, st_ctime=1329963124)
As we see, st_size is now seen by Python.
I’m stumped. Any ideas? I can post more code if necessary. Thank you.
You probably just forgot to flush.