Re: Localized month names?

2006-03-14 Thread Sibylle Koczian
Benji York schrieb:
 Jarek Zgoda wrote:
 
 How do I get a list of localized month names for current locale? The
 first thing that came to my mind was an ugly hack:
 
 
 import locale
 locale.nl_langinfo(locale.MON_1)
 'January'
 

What did you leave out? I get

Traceback (most recent call last):
  File pyshell#3, line 1, in -toplevel-
locale.nl_langinfo(locale.MON_1)
AttributeError: 'module' object has no attribute 'nl_langinfo'

(Python 2.4, german Windows XP Pro)

Moreover, 'January' is probably not localized.

-- 
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg
e-mail : [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Localized month names?

2006-03-14 Thread Peter Otten
Sibylle Koczian wrote:

 Benji York schrieb:
 Jarek Zgoda wrote:
 
 How do I get a list of localized month names for current locale? The
 first thing that came to my mind was an ugly hack:
 
 
 import locale
 locale.nl_langinfo(locale.MON_1)
 'January'
 
 
 What did you leave out? 

Nothing, most likely.

 I get 
 
 Traceback (most recent call last):
   File pyshell#3, line 1, in -toplevel-
 locale.nl_langinfo(locale.MON_1)
 AttributeError: 'module' object has no attribute 'nl_langinfo'
 
 (Python 2.4, german Windows XP Pro)
 
 Moreover, 'January' is probably not localized.

Python 2.4.2 (#4, Nov 19 2005, 13:25:59)
[GCC 3.3.3 (SuSE Linux)] on linux2
Type help, copyright, credits or license for more information.
 import locale
 locale.nl_langinfo(locale.MON_1)
'January'
 locale.setlocale(locale.LC_ALL, )
'de_DE.UTF-8'
 locale.nl_langinfo(locale.MON_1)
'Januar'


Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Localized month names?

2006-03-14 Thread Kent Johnson
Peter Otten wrote:
 Sibylle Koczian wrote:
What did you leave out? 
 
 
 Nothing, most likely.
 
 
I get 

Traceback (most recent call last):
  File pyshell#3, line 1, in -toplevel-
locale.nl_langinfo(locale.MON_1)
AttributeError: 'module' object has no attribute 'nl_langinfo'

(Python 2.4, german Windows XP Pro)

Moreover, 'January' is probably not localized.
 
 
 Python 2.4.2 (#4, Nov 19 2005, 13:25:59)
 [GCC 3.3.3 (SuSE Linux)] on linux2
 Type help, copyright, credits or license for more information.
 
import locale
locale.nl_langinfo(locale.MON_1)

 From the docs:
nl_langinfo(option)

 Return some locale-specific information as a string. This function 
is not available on all systems, and the set of possible options might 
also vary across platforms.

It doesn't seem to be available on Windows:
Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on 
win32
Type help, copyright, credits or license for more information.

In [1]: import locale

In [2]: locale.nl_langinfo(locale.MON_1)

Traceback (most recent call last):
   File ipython console, line 1, in ?
AttributeError: 'module' object has no attribute 'nl_langinfo'

Kent
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Localized month names?

2006-03-13 Thread Fredrik Lundh
Jarek Zgoda wrote:

 How do I get a list of localized month names for current locale? The
 first thing that came to my mind was an ugly hack:

 import datetime
 for i in range(12):
 # as I remember, all months in 2005 had 1st in days
 datetime.date(2005, i + 1, 1).strftime('%B')

doesn't look very ugly to me...

the strftime tables are hidden deep inside the C library, but I guess you
could use the _strptime implementation module to dig out the information
you're after:

 import locale
 locale.setlocale(locale.LC_ALL, sv_SE)
'sv_SE'
 import _strptime
 vars(_strptime.LocaleTime())
{'lang': ('sv_SE', 'ISO8859-1'), 'am_pm': ['', ''], 'f_month': ['', 'januari',
'februari', 'mars', 'april', 'maj', 'juni', 'juli', 'augusti', 'september', 
'oktober',
'november', 'december'], 'LC_date': '%Y-%m-%d', 'a_weekday': ['m\xe5n',
'tis', 'ons', 'tor', 'fre', 'l\xf6r', 's\xf6n'], 'f_weekday': ['m\xe5ndag', 
'tisdag',
'onsdag', 'torsdag', 'fredag', 'l\xf6rdag', 's\xf6ndag'], 'LC_date_time':
'%a %d %b %Y %H.%M.%S', 'timezone': (frozenset(['utc', 'cet', 'gmt']),
frozenset(['cest'])), 'a_month': ['', 'jan', 'feb', 'mar', 'apr', 'maj', 'jun',
'jul', 'aug', 'sep', 'okt', 'nov', 'dec'], 'LC_time': '%H.%M.%S'}

(I'm pretty sure _strptime uses your ugly hack-approach to extract this
information from the C library...)

hope this helps!

/F



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Localized month names?

2006-03-13 Thread Benji York
Jarek Zgoda wrote:
 How do I get a list of localized month names for current locale? The
 first thing that came to my mind was an ugly hack:

  import locale
  locale.nl_langinfo(locale.MON_1)
'January'

--
Benji York
-- 
http://mail.python.org/mailman/listinfo/python-list