python - Force locale for one function to be UK/English in just one function so that datetime.strftime always returns an English format -
i need write simple python function accepts date in excel format (an integer of days elapsed since 1st jan 1900). convert python datetime.date object, , i'd format shortened string date (e.g. "jan10" or "mar11") - date in mmmyy format.
dt.strftime( fmt )
this function works fine on uk & workstations, i've noticed on colleagues pcs set french locale wrong anser:
>>> locale.getdefaultlocale() ('fr_fr', 'cp1252')
on these machines function above returns formatted date-string in french not desired output.
i understand use locale.setlocale function globally re-define locale, not desirable. elsewhere in system there scripts require native-language locale. not wish break else's component re-defining global locale.
so can do? short of re-writing string-formatting function, there way can make strftime function produce it's output in uk/us locale without affecting else?
platform = python2.4.4 on windows 32bit
fyi, solution not apply - changes locale globally want avoid doing: locale date formatting in python
if need fixed strings it's best create mapping of month number month name , use that.
months = {1: 'jan', 2: 'feb', ...} printf '%s%02d' % (months[somedt.month], somedt.year % 100)
Comments
Post a Comment