473,769 Members | 6,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems wth os.stat().st_mt ime on Mac

The Python 2.5 News at
http://www.python.org/download/releases/2.5/NEWS.txt states that Python
2.5 was changed to "Use Win32 API to implement os.stat/fstat. As a
result, subsecond timestamps are reported, the limit on path name
lengths is removed, and stat reports WindowsError now (instead of OSError)."

Although not mentioned in the Python 2.5 News, apparently there was a
similar change on Mac that I'm having some problems with. On the Mac,
just as on Windows, os.stat().st_mt ime now returns a float instead of an
integer. My problem is that the decimal part of the float is
inconsistent in two ways.

1) The more serious problem (for me), is that on two machines (PowerPC
Mac Mini running Tiger and Intel Mac Mini running Tiger), the decimal
part of the returned float always appears to be ".0". On an iBook
running Panther, however, the decimal part appears to be ".0" for many
files, but for other files it contains actual significant digits. For
example:

import os
f = open("/tmp/tmp.tmp", "w")
f.close()
print os.stat("/tmp/tmp.tmp").st_mt ime

#Both Mac Minis: 1159536137.0
#iBook: 1159536233.08

a) Why the difference between machines?

Also, on the iBook, I created this listing:
>>for x in os.listdir("/tmp"): os.stat(os.path .join("/tmp",
x)).st_mtime, x
(1159466888.0, '502')
(1159469259.0, '505')
(1159472677.0, 'hsperfdata_bui ld')
(1159466868.0, 'mcx_compositor ')
(1159466908.0, 'SoftwareUpdate Check.pkgcatalo g')
(1159532547.240 5169, 'test.xxx')
(1159536233.079 4201, 'tmp.tmp')

b) Why do most files on this machine have ".0", while some (generally
those I created myself using Python 2.5, I think) don't?
2) Even on the same machine, the results are different depending on how
I access them. For example, after setting up as follows:

strPath = "/tmp/test.xxx"
f = open(strPath, "w")
f.close()

I get the following output:
>>os.stat(strPa th)
(33188, 1822331L, 234881030L, 1, 505, 0, 0L, 1159532547,
1159532547, 1159533628)
#Note that the results are all integers, including mtime
>>os.stat(strPa th).st_mtime
1159532547.2405 169
#The result has 7 decimal places

I understand how the results can be different: the os.stat() function
returns a posix.stat_resu lt object, which gives back an integer value
for the mtime if you call __str__ or __repr__, or if you iterate on it;
and a float if you get the st_mtime attribute. But I would consider it a
bug that the results are different: a float should be returned in either
case.
Mike

Sep 29 '06 #1
2 5052
Michael Glassford schrieb:
Although not mentioned in the Python 2.5 News, apparently there was a
similar change on Mac that I'm having some problems with. On the Mac,
just as on Windows, os.stat().st_mt ime now returns a float instead of an
integer.
It's isn't really new; os.stat_float_t imes was introduced in Python 2.3.
What changed in 2.5 is that it is now true. See

http://docs.python.org/whatsnew/modules.html
a) Why the difference between machines?
You really have to delve into OSX to answer this question. Several
reasons are possible:
- there is a change in the operating system implementations
- you are using different Python versions
- you are using different file systems
b) Why do most files on this machine have ".0", while some (generally
those I created myself using Python 2.5, I think) don't?
Hard to tell. Maybe the software that created those files explicitly
set a time stamp on them, and failed to use the API that supports
subsecond resolution in setting those time stamps.
I understand how the results can be different: the os.stat() function
returns a posix.stat_resu lt object, which gives back an integer value
for the mtime if you call __str__ or __repr__, or if you iterate on it;
and a float if you get the st_mtime attribute. But I would consider it a
bug that the results are different: a float should be returned in either
case.
That's for backwards compatibility: You shouldn't use the tuple
interface anymore, but use st_mtime for new code. This will always
be a float. OTOH, the tuple interface will continue to return
integers forever (or until the tuple interface is removed in Python
3000), as old applications will break. This breakage isn't theoretical:
when I introduced float into st_mtime, I first made the tuple be
float also, and it broke several applications within a week (even
though that code was just in the CVS trunk, and not released yet).

Regards,
Martin
Sep 29 '06 #2
Martin v. Löwis wrote:
Michael Glassford schrieb:
>Although not mentioned in the Python 2.5 News, apparently there was a
similar change on Mac that I'm having some problems with. On the Mac,
just as on Windows, os.stat().st_mt ime now returns a float instead of an
integer.

It's isn't really new; os.stat_float_t imes was introduced in Python 2.3.
What changed in 2.5 is that it is now true. See

http://docs.python.org/whatsnew/modules.html
Thanks, I wasn't aware of os.stat_float_t imes. This helps me a lot,
since I can turn off the floating point times in places until
incompatible code can be fixed.
>
>a) Why the difference between machines?

You really have to delve into OSX to answer this question. Several
reasons are possible:
- there is a change in the operating system implementations
Possible, I guess, although I don't know how to find out and there's
likely nothing I could do about it even if I did.
- you are using different Python versions
Python 2.5 on both.
- you are using different file systems
This is the first thing I thought of, but all of the drives are
formatted using "Mac OS Extended (Journalled)", which I assumed meant
they are using the same file system.
>
>b) Why do most files on this machine have ".0", while some (generally
those I created myself using Python 2.5, I think) don't?

Hard to tell. Maybe the software that created those files explicitly
set a time stamp on them, and failed to use the API that supports
subsecond resolution in setting those time stamps.
>I understand how the results can be different: the os.stat() function
returns a posix.stat_resu lt object, which gives back an integer value
for the mtime if you call __str__ or __repr__, or if you iterate on it;
and a float if you get the st_mtime attribute. But I would consider it a
bug that the results are different: a float should be returned in either
case.

That's for backwards compatibility: You shouldn't use the tuple
interface anymore, but use st_mtime for new code. This will always
be a float. OTOH, the tuple interface will continue to return
integers forever
<snip>

OK, thanks for the explanation.

Mike

Oct 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9542
by: Steven T. Hatton | last post by:
I found the following two statements in the file linked below: struct stat st; stat(fileName.c_str(), &st); http://websvn.kde.org/branches/work/kdevelop4-parser/main.cpp?rev=420247&view=markup This is from /usr/include/sys/stat.h which I'm pretty sure is what #include <sys/stat.h> is pulling in. I plain and simply do not understand what the above two lines of code do. Can someone please explain?
3
3948
by: David Bear | last post by:
I'm trying to use os.chmod and am refered to the stat module. Is there are explanation of: * S_ISUID * S_ISGID * S_ENFMT * S_ISVTX * S_IREAD * S_IWRITE * S_IEXEC
9
2200
by: Sheldon | last post by:
Good day Everyone, I am a still very new at learning C and I have thrown myself in the deep end. I started with a simple program and kept widening the scope. This has taught me many things about C and some, I must admit, have not really sunk in yet. Still, I push on. Now I am taken a library of C programs that were designed to read HDF files. I work on a Unix server and in Mandrake10. The program below is most likely broken but I cannot...
1
3185
by: jmalone | last post by:
I have a python script that I need to freeze on AIX 5.1 (customer has AIX and does not want to install Python). The python script is pretty simple (the only things it imports are sys and socket). The README file in the Tools/freeze directory of the Python-2.4.4 distribution says the following (and many other things): Previous versions of Freeze used a pretty simple-minded algorithm to
6
1773
by: Hansen | last post by:
Hi Group, I've made a statistic module for our framework, and have put it in a namespace called stat (which resides in a namespace called dao) My problem is that now the compiler thinks that it is the struct called stat from wchar.h that I'm refering to even though I've written dao::stat::stat_base I have included the stat_base.h header and have checked for using statements, but nothing seems to work.
24
6127
by: Joe Salmeri | last post by:
I just upgraded from Python 2.4.2 to Python 2.5.1 and have found some unexpected behavior that appears to be a bug in the os.stat module. My OS is Windows XP SP2 + all updates. I have several programs that have worked flawlessly on all previous Python versions for years and they are now producing incorrect results in the code that uses os.stat. Searching through the 2.5.1 release notes I found the following:
2
2965
by: patrickdepinguin | last post by:
Hi, I use zlib to write data structures to a compressed file, using the gzwrite function. Afterwards I read the data back with gzread. I notice that this works well when the data written is not that much, but when there is more data to write, after a while I get data errors when reading back the data. Error in main: couldn't read stat zlib error -3: test512-20070531-18h10m02.stat.gz: data error
3
5265
by: Magesh | last post by:
How date-time attributes of a file are represented in the structure "struct stat"? Coz as I noted they found to be unsigned integers and I donno how they are interpreted as date & time in the members st_atime, st_mtime, and st_ctime. I don't want any lib fun that returns the corresponding time formatted string coz what I want to know is the interpretation of date-time in those members so that I could extract them and use it for some...
3
7010
by: Deniz Dogan | last post by:
Hello. I have a question regarding the st_mode field of the "stat" struct in sys/stat.h. I'd like to know how to use the S_IRWXU, S_IRWXG and S_IRWXO flags to mask the mode_t value into human readable form such as 755, 644, etc. Currently I do something similar to this: usr_t = (mod & S_IRWXU); usr_r = (mod & S_IRUSR);
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7409
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.