Solved

Code Interpretation Needed

Posted on 2015-02-24
6
91 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 36

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 36

Expert Comment

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Starting up a Project

615 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