Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

how to convert this basic calendar script into a function?

hi, I@m trying to get this to work as a function, in Pyhon 3 - struggling a little here, can anyone help, thanks 🙂


import calendar
c = calendar.TextCalendar(calendar.MONDAY)
c.prmonth(2018, 5)
I'm not sure if this is what you meant exactly, and it could probably be done much better. Basically what I did was import datetime to get the date information, and I called it with a function to print a text calendar of the current month.
Code
import calendar
import datetime # Allows us to get the current date.


def calendar_today(): # Defines a function
    now = datetime.datetime.now() # Stores today's date as a variable
    c = calendar.TextCalendar(calendar.SUNDAY) # Formats the calendar to start with sunday
    month = c.formatmonth(now.year, now.month) # Formats the calendar to this year and month
    print(month) # Prints the calendar stored in the previous variable

calendar_today() # Calls the function
great, thanks - that works fine

now, I'm going try and get it working online with Flask - that could be tricky for me! do you know much about doing that?
I do not, sorry. I'm actually not very good at python, still learning a lot myself. From what I've read, the best idea is to use JavaScript for a calendar in flask.
ok, cheers, I'll see if I can get the calendar up and running on flask for now


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by FhackMar 2, 2022 03:52 AM 4 307 Mar 2, 2022 03:52 AM
Last Post: Fhack
[Python] by pottedsyeniteMay 20, 2019 09:46 AM 2 141 May 20, 2019 09:46 AM
Last Post: pottedsyenite
[C] by eyehollowOct 19, 2018 09:19 AM 1 252 Oct 19, 2018 09:19 AM
Last Post: Auriana