Issue 27382: calendar module .isleap() probleam (original) (raw)
Issue27382
Created on 2016-06-24 14:52 by Dyl Tuckey, last changed 2022-04-11 14:58 by admin. This issue is now closed.
Messages (3) | ||
---|---|---|
msg269183 - (view) | Author: Dyl Tuckey (Dyl Tuckey) | Date: 2016-06-24 14:52 |
I don't know why but whenever I try and run this code: import calendar import time calendar = calendar.month(2016,6) print ("Loading date, time, month and leap year status") time.sleep(5) print (calendar) localtime = time.asctime(time.localtime(time.time())) print (localtime) if calendar.isleap(2016) == True: print("This year is a leap year") else: print("This year is not a leap year") It come up with: Loading date, time, month and leap year status June 2016 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 Fri Jun 24 15:46:12 2016 Traceback (most recent call last): File "C:\Users\Dylan\Desktop\Python\Calendar.py", line 9, in if calendar.isleap(2016) == True: AttributeError: 'str' object has no attribute 'isleap' And I don't know why I keep getting error messages | ||
msg269184 - (view) | Author: Anilyka Barry (abarry) * ![]() |
Date: 2016-06-24 14:56 |
You're overriding the 'calendar' variable, holding the module, by the result of your 'calender.month' call, which happens to be a str. Use a different variable name (e.g. 'result') and the error will disappear. Unrelated, but don't check for 'if x == True' - just do 'if x' and the result will be the same (also allows for any other result than booleans). | ||
msg269191 - (view) | Author: Dyl Tuckey (Dyl Tuckey) | Date: 2016-06-24 16:40 |
Thank you ebarry. I would probably never have figured that out |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:58:33 | admin | set | github: 71569 |
2016-06-24 16:40:27 | Dyl Tuckey | set | messages: + |
2016-06-24 14:56:31 | abarry | set | status: open -> closedtype: compile error -> components: - IDLEnosy: + abarrymessages: + resolution: not a bugstage: resolved |
2016-06-24 14:52:56 | Dyl Tuckey | create |