954,176 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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
 

I'm not very certain on classes and stuff like that myself but i'm guessing and from what i've read i think if you do

class namehere(calender_name):
    stuff here

can't guarantee it will work (not on my computer so i can't get at python to try it)
but it's just an idea

a1eio
Junior Poster
141 posts since Aug 2005
Reputation Points: 26
Solved Threads: 25
 

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
Moderator
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
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You