Inherit Calendar
I am just starting to look at writing class in Python. Can a class that I write inherit Python calendar?
bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184
You can only inherit another class. The module calendar contains a function calendar, but you can't inherit a function. This small code might explain a few basic things ...
import calendar
import Cookie
import inspect
if inspect.isclass(calendar):
print "calendar is a class"
else:
print "calendar is not a class"
# this would give you an error since calendar is not a class, but a module
# there is a function (not a class) calendar within module calendar
# you can use functions like calendar.calendar(), but not inherit them
"""
class MyCalendar(calendar):
pass
"""
if inspect.isclass(Cookie.Morsel):
print "Cookie.Morsel is a class"
else:
print "Cookie.Morsel is not a class"
# this will work, since Morsel is a class in module Cookie
class MyCookie(Cookie.Morsel):
"now do something more than pass"
pass
print type(calendar) # <type 'module'>
print type(calendar.calendar) # <type 'function'>
print type(Cookie) # <type 'module'>
print type(Cookie.Morsel) # <type 'type'> hint of class
Note: A class name by convention starts with a capital letter, this can be a hint!
vegaseat
DaniWeb's Hypocrite
5,976 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,416
I am astonished how little classes basic Python modules uses. I thought it was more of a OO language.
bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184