Solved

Code Interpretation Needed

Posted on 2015-02-24
6
84 Views
Last Modified: 2015-02-24
def _submit_callback(self):
       
 Looking at this snippet, what is the :

 self.months.index(self.end_month.get()) + 1,   doing?

Is there something there that will get say the ending month as count the number of days in that month?    


   # check that the input values are a real, legitimate date
        try:      
            start = date(int(self.start_year.get()),
                         self.months.index(self.start_month.get()) + 1,
                         int(self.start_day.get()))
           
            end = date(int(self.end_year.get()),
                         self.months.index(self.end_month.get()) + 1,
                         int(self.end_day.get()))
0
Comment
Question by:xoxomos
  • 3
  • 2
6 Comments
 

Author Comment

by:xoxomos
ID: 40629472
It's in some Python code i'm looking at.
0
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 40629662
This is only a guess from the (very) limited amount of info that you've provided, but..


self.end_month       is probably a field of some sort that accepts the month, possibly as a string, ie. JAN or FEB, etc

self.end_month.get()       returns that month as a string, ie. "JAN"

self.months       is an array on all the month names as strings, ie. [ "JAN", "FEB", "MAR", "APR", .... ]

self.months.index()       looks up the array to find the index given a value passed in, so...

self.months.index(self.end_month.get())       if the end_month was "JAN", it will find "JAN" in the array which is at index = 0 and so return 0 (Note, array indexes are 0 based, ie. the first item in the array is index 0, the second item is index 1, etc)

self.months.index(self.end_month.get()) + 1       just adds 1 to the index retrieves. This is to cater for the above fact that indexes are 0 based. So if the end_month is "JAN", the index in the array will be 0 and then we add 1, so the result is 1 which is what the date() function would require, ie. the months of the year, "JAN" -> "DEC" have indexes in the 0 -> 11 so we add one to get the range 1 -> 12
0
 

Author Comment

by:xoxomos
ID: 40629666
Makes so much sense.  Mil gracias.
0
 

Author Closing Comment

by:xoxomos
ID: 40629668
Thanx
0
 
LVL 35

Expert Comment

by:mccarl
ID: 40629681
You're welcome! :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now