Date manipulation and Java 'interface' equivalents

Darrell Gallion darrell at dorb.com
Sun Nov 5 18:34:40 EST 2000


From: "Martin Christensen":
>
> First of all, I am doing some statistics with a PostgreSQL database,
> and for this I need to manipulate some dates, ie. add a week to this
> date or subtract a month from another. I didn't find any obvious
> candidates for this kind of date math in the library reference. Now,
> _of course_ this can be done in Python rather than forcing me to use
> the DBMS for this, but... erm... how?
>
Check out mxDateTime
http://starship.python.net/~lemburg/mxExtensions.html


> Second question: is there a Python equivalent of Java interfaces?

Yes, but not the same.
I'm not a Java expert, but I believe interfaces provide a compile time
check.
Allows the Java compiler to validate a call and all of it's type info. Much
like pure abstract base classes in C++.

Refugees from those authoritarian languages have to unlearn the rigid
thinking.

These two classes share a common interface and could be used in some cases
where a file pointer is expected.
But A().read() will produce AttributeError:

class A:
    def write(self, s):
        print "A:", s

class B:
    def write(self, s):
        print "B:", s

Found a couple hits on deja.com
http://x53.deja.com/getdoc.xp?AN=561186674.1&CONTEXT=973460437.52625415&hitn
um=47
http://x53.deja.com/getdoc.xp?AN=623535185&CONTEXT=973460437.52625415&hitnum
=54
http://x53.deja.com/getdoc.xp?AN=623535185&CONTEXT=973460437.52625415&hitnum
=54

--Darrell







More information about the Python-list mailing list