question on the 'calendar' function

Calvin Spealman cspealma at redhat.com
Wed Nov 21 09:09:00 EST 2018


You really have the pieces you need here. You can print a whole year's
calendar with calendar.formatyear() or a single month with
calendar.monthcalendar(). If you need multiple years, call the first more
than once with each year you need to print. If you need partial years,
print the individual months you need with monthcalendar()

Can you actually be more specific on what about the task is stumping you?

On Wed, Nov 21, 2018 at 7:28 AM o1bigtenor <o1bigtenor at gmail.com> wrote:

> On Wed, Nov 21, 2018 at 2:37 AM <marco.nawijn at colosso.nl> wrote:
> >
> > On Tuesday, November 20, 2018 at 7:53:06 PM UTC+1, o1bigtenor wrote:
> > > On Tue, Nov 20, 2018 at 11:50 AM Schachner, Joseph
> > > <Joseph.Schachner at teledyne.com> wrote:
> > > >
> > > > It's possible I don't understand the question.  The calendar
> functions are NOT limited to this year or any limited range.
> > > >
> > > > Example:
> > > > import calendar
> > > > print( calendar.monthcalendar(2022, 12) )
> > > >
> > > > Prints lists of dates in each week of December 2022.  It prints:
> > > > [[0, 0, 0, 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]]
> > > >
> > > > So, Dec 1 is a Wednesday; Dec 31 is a Saturday.
> > > >
> > > > That's 49 months ahead of this month.   Change the year and month to
> any (valid) number, and it will do what it does.
> > > > The only caveat is that if the moon's orbit slows down as it gets
> farther away from the earth and the earth's rotation speed changes, then
> the calculations done by calendar for leap years may not be correct about
> the distant future.
> > > >
> > >
> > > Greetings
> > >
> > > If my syntax or commands are wrong - - - - I've just started so
> > > something is likely to NOT be correct - - - grin - - - I'sa noob!
> > >
> > > # calendar 2019
> > >
> > > that is to show the year 2019
> > >
> > > How could I show June 2018 to Dec 2019, inclusive?
> > > Or June 2018 to Dec 2021, inclusive?
> > > Or June 2018 to Dec 2023 by week (June wk 1,2,3,4 2018; July wk
> > > 1,2,3,4,5 2018; . . .   Dec wk 1,2,3,4,5 2023 or maybe even by dates),
> > > inclusive?
> > >
> > > Note that the time frame is ALWAYS more than 1 year.
> > > AIUI there isn't a way to do that, at least not that I can see, and I
> > > would like to be able to do that.
> > > A friend suggested using a script wrapped around the command. I
> > > thought maybe there might we a way of doing what I need to do without
> > > using 2 levels of programming.
> > >
> > > Regards
> >
> > From what you post it seems like you are on a Linux kind of system and
> you are running the `calendar` command in the bash terminal. If that is
> correct, try the following:
> >
> > In the bash terminal type (without the literal #):
> > # python
> >
> > This will put you in the Python prompt (marked with >>>).
> > Check that the first line starts with Python 3. If not, I highly
> recommend
> > you install Python 3. If it is Python two, the following will work, but
> you
> > have to drop the outer parentheses for print (thus print
> calendar.calendar())
> >
> > Then type the following:
> > >>> import calendar
> > >>> print(calendar.calendar(2020))
>
> > Now look at the documentation of the calendar module to find out about
> > other options.
> >
>
> Thank you very much Mr Marco - - - that got me to being able to do
> something
> (will need time to figure out how to do the rest! grin!!).
> I have read through the documentation and there really doesn't seem to be
> a way
> to do what I would like to do - - - - in this case.
>
> What I can't do is (following your directions)
>
> >>> import calendar
> >>> print(calendar.calendar(Mar 2018 to Dec 2023))
>
> What I need is to be able to have more than one calendar year options and
> this
> function seems to be limited to work with a maximum of only one year at a
> time.
>
> If I not reading the documentation correctly - - - please advise.
> (Thanking you for your generous assistance in the foregoing!)
>
> Regards
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list