Python Note: Get the current month

There are various formats to take out, and it seemed to be complicated, so make a note. Basically, use a module called calendar.

import calendar

cal = calendar.Calendar()    #Create calendar object
# calendar.Calendar(1)You can specify the day of the week to be treated at the beginning of the week. 0~6 and the default is 0 (Monday).

###Income the schedule as decided in the above Calendar class. There are the following formats.###

cal.itermonthdays(int_year,int_month)
#Iterator format. You can take out the days in order.

cal.itermonthdays2(int_year,int_month)
#You can get the day of the week as well as the day. (Day,week_Get tuples called num) in order.

cal.itermonthdates(int_year,int_month)
#This is datetime.date(year,month,day)Form of.

cal.monthdayscalendar(int_year,int_month)
# [[0,0,1,2,3,4,5],[6,7..],[...]]With that feeling, you can take the days of each week in an array.

###Please note that the end of the month or the beginning of the month may come in during the week of the beginning or end of the month!


##By the way, if you want to know only the number of days in a month##
calendar.monthrange(int_year,int_month)
#OK. The day of the week (I wonder if it is necessary ...) and the total number of days are returned as tuples.

Recommended Posts

Python Note: Get the current month
[Python] Get the previous month
python get current time
Get last month in python
[Python] Check the current directory, move the directory
Get the desktop path in Python
Get the weather with Python requests
Get the weather with Python requests 2
Get the script path in Python
How to get the Python version
Note: Python
Get the current date and time in Python, considering the time difference
Python note
Calculate the previous month in Python
Get the host name in Python
Command for the current directory Python
Note: Get the first and last items of Python OrderedDict non-destructively
[Python] How to get the first and last days of the month
[Note] Get data from PostgreSQL with Python
[Python] Get the variable name with str
Get the last day of the specified month
[Python] Get the character code of the file
Get the EDINET code list in Python
Python Note: The secret role of commas
[Python] Get the main color from the screenshot
Python study note_002
Note: Python Decorator
Python programming note
[Python] Learning Note 1
Python study note_004
Python study note_003
Get and convert the current time in the system local timezone with python
[Note] openCV + python
Get the contents of git diff from python
[Python] Get the files in a folder with Python
Get the weather in Osaka via WebAPI (python)
[Python] Get / edit the scale label of the figure
[Note] Export the html of the site with python.
[Python] Get the main topics of Yahoo News
Get the caller of a function in Python
Get note information using Evernote SDK for Python 3
A note about the python version of python virtualenv
[Python] Get the last updated date of the website
How to get the files in the [Python] folder
[Python] Get the day of the week (English & Japanese)
Python script to get note information with REAPER
Get the update date of the Python memo file.
Find the maximum Python
[Python] Get environment variables
Python note: When the pip command cannot be used
How to get the variable name itself in python
[Note] future sentence ~ Python ~
[Note] File reading ~ Python ~
How to get the number of digits in Python
Note the frequently used options in Python + Selenium + Chrome
[Python] Extract the video ID from the YouTube video URL [Note]
How to know the current directory in Python in Blender
[Python] Get the text of the law from the e-GOV Law API
[Python] Get Qiita trends
[Python] Get the numbers in the graph image with OCR
Get the SQL executed by dataset (Python OR mapper)