[Baypiggies] strftime("%x") inconsistent?

Paul McNett p at ulmcnett.com
Tue Nov 10 00:57:09 CET 2009


Paul McNett wrote:
> Hi,
> 
> I'm using python 2.5.4 (sorry, been meaning to go to 2.6 or 2.7 but I've 
> been too busy to take the plunge yet, and I can't consider going to 3.x 
> until there's more 3rd-party lib support).
> 
> Anyway, I want to give a textual representation of a date or datetime 
> using the user's current locale setting. I don't want to explicitly set 
> the format as I think this should be up to the user.
> 
> The following code results in the expected output (match the 'short 
> date' format in Control Panel/Regional Settings) on Windows XP, but not 
> on Mac 10.5.7 or Ubuntu 8.04:
> 
> {{{
> import locale
> import datetime
> import time
> 
> locale.setlocale(locale.LC_ALL, "")
> 
> d = datetime.date.today()
> 
> print time.strftime("%x", d.timetuple())
> }}}
> 
> Am I forgetting a step?

Ok, the only inconsistency is how Windows works, I guess. On Linux and Mac, the LANG 
environmental variable determines which locale's date format we use. So in order to 
see the format change, I need to run my test program in a new terminal each time so 
that $LANG reflects the current value in System Preferences. On Windows, I guess 
there's a different mechanism to determine $LANG so I didn't need to restart the 
terminal on that platform.

Thanks and sorry for the noise.

Paul


More information about the Baypiggies mailing list