Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Code Interpretation Needed

Posted on 2015-02-24
6
Medium Priority
?
94 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 2000 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
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 …
Simple Linear Regression

721 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