Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8723101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:33:00+00:00 2026-06-13T07:33:00+00:00

I am playing with Python’s calendar module that’s in the standard library. Basically I

  • 0

I am playing with Python’s calendar module that’s in the standard library. Basically I need a list of all days of a month, like so:

>>> import calendar
>>> calobject = calendar.monthcalendar(2012, 10)
>>> print calobject
[[1, 2, 3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14], [15, 16, 17, 18, 19, 20, 21], [22, 23, 24, 25, 26, 27, 28], [29, 30, 31, 0, 0, 0, 0]]

Now what I also need are the names of the months and days in a specific locale. I didn’t find a way to get these from the calobject itself – but I was able to get them like so:

>>> import calendar
>>> calobject = calendar.LocaleTextCalendar(calendar.MONDAY, 'de_DE')
>>> calobject.formatmonth(2012, 10)
'    Oktober 2012\nMo Di Mi Do Fr Sa So\n 1  2  3  4  5  6  7\n 8  9 10 11 12 13 14\n15 16 17 18 19 20 21\n22 23 24 25 26 27 28\n29 30 31\n'

So Oktober is the de_DE name for october. Fine. The information must be there. I’m wondering if I can access that month name somehow on a plain calendar object instead of a calendar.LocaleTextCalendar object. The first example (with the list) is really what I need and I don’t like the idea to create two calendar objects to get localized names.

Anyone got a smart idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:33:01+00:00Added an answer on June 13, 2026 at 7:33 am

    This is from the source code of the calendar module:

    def formatmonthname(self, theyear, themonth, width, withyear=True):
        with TimeEncoding(self.locale) as encoding:
            s = month_name[themonth]
            if encoding is not None:
                s = s.decode(encoding)
            if withyear:
                s = "%s %r" % (s, theyear)
            return s.center(width)
    

    TimeEncoding and month_name can be imported from the calendar module. This gives the following method:

    from calendar import TimeEncoding, month_name
    
    def get_month_name(month_no, locale):
        with TimeEncoding(locale) as encoding:
            s = month_name[month_no]
            if encoding is not None:
                s = s.decode(encoding)
            return s
    
    print get_month_name(3, "nb_NO.UTF-8")
    

    For me the decode step is not needed, simply printing month_name[3] in the TimeEncoding context prints “mars”, which is norwegian for “march”.

    For weekdays there’s a similar method using the day_name and day_abbr dicts:

    from calendar import TimeEncoding, day_name, day_abbr
    
    def get_day_name(day_no, locale, short=False):
        with TimeEncoding(locale) as encoding:
            if short:
                s = day_abbr[day_no]
            else:
                s = day_name[day_no]
            if encoding is not None:
                s = s.decode(encoding)
            return s
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been playing with Python and I have this list that I need worked
I'm playing around with 2 objects {@link http://docs.python.org/library/datetime.html#datetime.date } I would like to calculate
What is a good module for playing wav files for Python 2 that would
I was playing around with Python's subprocess module, trying a few examples but I
I've been playing around with Python's imaplib and email module recently. I tried sending
So I've been playing around with python and noticed something that seems a bit
I am playing with Google App Engine and Python and I cannot list the
I'm playing around with networkx (graph library in python) and I found documentation saying
I have been playing around with Python's FTP library and am starting to think
I've been playing with various ways of doing literate programming in Python. I like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.