473,799 Members | 3,866 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inheriting from datetime

So this is simple, why can't I run the following code? I've tried many
variances of this, but simply cannot inherit from datetime or
datetime.dateti me. I get this on line 3.
TypeError: function takes at most 2 arguments (3 given)

*************** *************** **
import datetime
_datetime = datetime.dateti me

class MyDateTime(_dat etime):
"""
Identical to builtin datetime.dateti me, except it accepts
invalid dates and times as input.
"""
_valid = True

def __init__(self, year, month, day, *args, **kw):
try:
_datetime.__ini t__(self, year, month, day, *args, **kw)
except _datetime.Value Error:
_valid = False
self.year = year
self.month = month
self.day = day
self.args = args
self.kw = kw
*************** *************** **

Aug 1 '05 #1
4 2738
On 2005-08-01, Rob Conner <rt******@gmail .com> wrote:
So this is simple, why can't I run the following code? I've tried many
variances of this, but simply cannot inherit from datetime or
datetime.dateti me. I get this on line 3.
TypeError: function takes at most 2 arguments (3 given)


I think I posted this question a while back and the problem was
that a datetime instance is not mutable, so the normal method
of deriving a class didn't work....

A quick google...

http://groups-beta.google.com/group/...2517ecf6fb2ce/

You need to override __new__ rather than __init__

--
Grant Edwards grante Yow! I'm ANN LANDERS!! I
at can SHOPLIFT!!
visi.com
Aug 1 '05 #2
On 2005-08-01, Rob Conner <rt******@gmail .com> wrote:
So this is simple, why can't I run the following code? I've tried many
variances of this, but simply cannot inherit from datetime or
datetime.dateti me. I get this on line 3.
TypeError: function takes at most 2 arguments (3 given)

*************** *************** **
import datetime
_datetime = datetime.dateti me

class MyDateTime(_dat etime):
"""
Identical to builtin datetime.dateti me, except it accepts
invalid dates and times as input.
"""
_valid = True

def __init__(self, year, month, day, *args, **kw):
try:
_datetime.__ini t__(self, year, month, day, *args, **kw)
except _datetime.Value Error:
_valid = False
self.year = year
self.month = month
self.day = day
self.args = args
self.kw = kw
*************** *************** **


It helps to post the actual code and error message you
are seeing...
import datetime
class foo(datetime): .... pass
....
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: function takes at most 2 arguments (3 given) class foo(datetime.da tetime): .... pass
.... d = foo() Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: function takes at least 3 arguments (0 given) d = foo(1, 2, 3)
d foo(1, 2, 3, 0, 0) datetime.dateti me(1, 2, 3)

datetime.dateti me(1, 2, 3, 0, 0)

My guess is that the code you posted is not really the
code you were runnning.
Aug 1 '05 #3
Rob Conner wrote:
So this is simple, why can't I run the following code? I've tried many
variances of this, but simply cannot inherit from datetime or
datetime.dateti me. I get this on line 3.
TypeError: function takes at most 2 arguments (3 given)


line 3 of the following code or line 3 of the use of the code?

on my box it runs, except that ValueError is not caught by the except.

side question: what is the point of accepting invalid dates?

--
rafi

"Imaginatio n is more important than knowledge."
(Albert Einstein)
Aug 1 '05 #4
gah, yeah that was strange. but i got it now. thanks.
side question: what is the point of accepting invalid dates?

thats a long story. but it would be nice to have invalid dates at least
just stored. so i want to try to put a class together that does it.

Aug 1 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1878
by: richardlane | last post by:
Hi, basic question here - I'm struggling with the transfer from asp to asp.net a bit, especially in seeing the 'bigger picture' of how things are best structured. I have a website made up primarily of aspx pages. I have separated out the common <head> as an .ascx file and intend to do the same for other common regions of html. In the aspx.vb I have code that is common to all pages. For example a sub which is passed a parameter to tell...
15
1715
by: JustSomeGuy | last post by:
this doesn't want to compile.... class image : public std::list<element> { element getElement(key k) const { image::iterator iter; for (iter=begin(); iter != end(); ++iter) { element &elem(*iter);
29
5906
by: shaun roe | last post by:
I want something which is very like a bitset<64> but with a couple of extra functions: set/get the two 32 bit words, and conversion to unsigned long long. I can do this easily by inheriting from bitset<64>, but I know that STL has no virtual destructor. Can I get around this by calling the baseclass destructor explicitly in my derived class? Is there another way to get all of the bitset<64> functionality without rewriting a lot of...
1
2447
by: john diss | last post by:
hello there everyone.. I have created a class called "ProcessLog" inheriting from XmlDocument and two classes ("UploadedItem", "ProcessError") inheriting from XmlElement. I then have two classes ("UploadedTemplate", "UploadedPresentation") which inherit from "UploadedItem")... so far so good. I have overriden the CreateElement method of "ProccessLog" and it creates the correct elements as expected. The problem is I need to override...
11
2169
by: Noah Coad [MVP .NET/C#] | last post by:
How do you make a member of a class mandatory to override with a _new_ definition? For example, when inheriting from System.Collections.CollectionBase, you are required to implement certain methods, such as public void Add(MyClass c). How can I enforce the same behavior (of requiring to implement a member with a new return type in an inherited class) in the master class (similar to the CollectionBase)? I have a class called...
1
1178
by: luminousc | last post by:
Hi guys, I'm still a relative newbie at oop, as my background has been in old fashioned vanilla ASP, so please try to make your responses as simple as possible. I'm having issues with inheritence in my c#.net app. I've built a basic web control with some members and properties. I'm now trying to create a more specific class that uses all the base properties and then adds some more for a specific purpose. I can't seem to find the right...
2
1814
by: Charles Law | last post by:
I want a set of controls that all have a border, like a group box. I thought I would create a base control containing just a group box from which my set of controls could inherit. Assuming that this is the right approach (please tell me if it is not), how then do I make it so that the group box cannot be moved around on my set of controls, but is also able to act as container for other controls? If I leave the modifier of the group box...
3
5388
by: Alex Satrapa | last post by:
There's some mention in the (old!) documentation that constraints such as foreign keys won't include data from inheriting tables, eg: CREATE TABLE foo ( id SERIAL PRIMARY KEY ); CREATE TABLE bar ( attribute integer NOT NULL ) INHERITS (foo);
5
1928
by: UJ | last post by:
I have a user control that inherits from the standard windows text box. I have a routine that adds stuff to it. I have compiled it into a dll. I have added it to my app and I can debug into it. I can see that the text changes but it doesn't actually update on the screen (the text itself is correct in the routine in the object but the display is wrong.) I've tried invalidating the object after I change the text but it still doesn't display...
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9543
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10488
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10029
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7567
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6808
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.