Solved

Code Interpretation Needed

Posted on 2015-02-24
6
88 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Difference between List and Array in Python 5 114
ejb wildfly example 2 72
Python 3.5.2 - Script Help 3 92
error with datetime python 1 35
This is an explanation of a simple data model to help parse a JSON feed
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

756 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