-1

In the given code below I want to get the current month (October if I run it today) instead of "current_month" in monthpage which is "file/monthly/current_month".

How can it be done?

def CurrentMonth(self):  
    monthpage = "file/monthly/current_month"
    page = Page
    old_text = page.get(get_redirect=True)
martineau
  • 119,623
  • 25
  • 170
  • 301
DotBotHCV
  • 33
  • 1
  • 6
  • What is your data like? – Trollsors Oct 16 '19 at 05:13
  • I don't know if I get your question correctly, but if you want the month that the program is executed in, refer to this post about how to use the `datetime` library: https://stackoverflow.com/questions/30071886/how-to-get-current-time-in-python-and-break-up-into-year-month-day-hour-minu – lobetdenherrn Oct 16 '19 at 05:17
  • https://stackoverflow.com/questions/28189442/datetime-current-year-and-month-in-python – Pratik Oct 16 '19 at 05:17

3 Answers3

2
from datetime import datetime
now = datetime.now()
monthpage.replace('current_month',now.strftime("%B"))

It replaces the "current_month" string in monthpage variable with actual current month name

0

Simple. Use the datetime library !!

import datetime
mydate = datetime.datetime.now()
mydate.strftime("%B")
Saswath Mishra
  • 309
  • 2
  • 10
0

the simplest way :

import datetime
current_month = datetime.now().month()