944,198 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 2311
  • Python RSS
Sep 21st, 2005
0

Inherit Calendar

Expand Post »
I am just starting to look at writing class in Python. Can a class that I write inherit Python calendar?
Similar Threads
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
bumsfeld is offline Offline
1,422 posts
since Jul 2005
Sep 22nd, 2005
0

Re: Inherit Calendar

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
Python Syntax (Toggle Plain Text)
  1. class namehere(calender_name):
  2. 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
Reputation Points: 26
Solved Threads: 24
Junior Poster
a1eio is offline Offline
140 posts
since Aug 2005
Sep 23rd, 2005
0

Re: Inherit Calendar

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 ...
python Syntax (Toggle Plain Text)
  1. import calendar
  2. import Cookie
  3. import inspect
  4.  
  5. if inspect.isclass(calendar):
  6. print "calendar is a class"
  7. else:
  8. print "calendar is not a class"
  9.  
  10. # this would give you an error since calendar is not a class, but a module
  11. # there is a function (not a class) calendar within module calendar
  12. # you can use functions like calendar.calendar(), but not inherit them
  13. """
  14. class MyCalendar(calendar):
  15. pass
  16. """
  17.  
  18. if inspect.isclass(Cookie.Morsel):
  19. print "Cookie.Morsel is a class"
  20. else:
  21. print "Cookie.Morsel is not a class"
  22.  
  23. # this will work, since Morsel is a class in module Cookie
  24. class MyCookie(Cookie.Morsel):
  25. "now do something more than pass"
  26. pass
  27.  
  28.  
  29. print type(calendar) # <type 'module'>
  30. print type(calendar.calendar) # <type 'function'>
  31.  
  32. print type(Cookie) # <type 'module'>
  33. 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!
Last edited by vegaseat; Oct 1st, 2009 at 4:59 pm.
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Sep 25th, 2005
0

Re: Inherit Calendar

I am astonished how little classes basic Python modules uses. I thought it was more of a OO language.
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
bumsfeld is offline Offline
1,422 posts
since Jul 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Python's Profiler
Next Thread in Python Forum Timeline: see my errors :-(





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC