Graham Dumpleton wrote ..
> Okay, false alarm (I think). Have got myself worked up over nothing.
> I missed something very important:
> 
>   timestamp = fstat(opened.fileno())[-2]
> 
> That is the '[-2]' in the above.
> 
> I feel like a goose now.

Now for some explaination of why my brain turned off and I didn't see
the '[-2]'. My excuse is that personally I wouldn't use negative
indexing from the end of the stat structure. It therefore didn't look
like what I would use and I got confused. I don't use '[-2]' as I am
not sure you can.

Quoting the Python documentation, it suggests that the tuple
returns may actually contain more than 10 values.

  For backward compatibility, the return value of stat() is also
  accessible as a tuple of at least 10 integers giving the most important
  (and portable) members of the stat structure, in the order st_mode,
  st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime,
  st_ctime. More items may be added at the end by some implementations.
  The standard module stat defines functions and constants that are useful
  for extracting information from a stat structure. (On Windows, some
  items are filled with dummy values.)

Thus, I would always use:

  timestamp = fstat(opened.fileno())[stat.ST_MTIME]

The use of '[-2]' might not actually be portable and thus stat.ST_MTIME
should probably be used.

> I still though question why file/fstat is done and not stat/file though.
> Ie., why open the file to stat it?

Should clarify that latter would be stat/file/fstat to be totally
accurate. In other words, use stat() to determine if it has changed,
then open file and then fstat() to make sure have the true modification
time in case it just changed. Even though there is a double stat, this
only occurs when file changes. In balance, I would have thought this
would still be better than opening the file every time. Yes/No?

Graham

Reply via email to