David Madore's WebLog: A script in Python

[Index of all entries / Index de toutes les entréesLatest entries / Dernières entréesXML (RSS 1.0) • Recent comments / Commentaires récents]

↓Entry #0338 [older| permalink|newer] / ↓Entrée #0338 [précédente| permalien|suivante] ↓

(Saturday)

A script in Python

I've written my first program in Python: it's a cgi script which computes and displays the Gregorian solar and lunar calendars for any given year. I had started writing it in Perl, but I realized that Perl has no operator for integer division (!!!) and I need a lot of integer divisions in that script. So I gave up on Perl and decided to use Python instead.

Incidentally, I'm amazed by how few programming languages have a “sane” behavior for integer division and integer modulus when the dividend is negative: namely for (-2)/5 to be -1 (and not 0) and for (-2)%5 to be 3 (and not -2); apparently this is because (most?) silicon implementations have the totally ludicrous behaviour which makes (-2)/5 equal to 0 (so that (3-5)/2 is not equal to 3/2-1, which is really stupid). Anyway, Python has the sane behavior, whereas C does not.

I'm not enthusiastic: Python has some annoying misfeatures, for example the lack of the ternary x?y:z construction of C/C++/Perl, or a print construct which automatically adds a newline. On the other hand, Python is definitely cleaner than Perl (that's not too hard, though!) and has some nice features (I very much like the formatting % operator).

Anyway, you can see, with the names I had suggested for the lunar months, that today (November 8 of 2003) is Novil 14 of 2003. Consequently, it is a full moon (theoretical full moons fall on the 14th of every lunar month, and they agree more or less accurately with real full moons: typically to within a day). Actually, it is better than that: there is a full lunar eclipse tonight (maximality is at 2003-11-09T01:19Z). (For those who wonder why I'm not writing Full Moon next to this 'blog's entry, it is because I align the Moon phases indications on universal time and the full moon is ever so slightly past midnight GMT.)

↑Entry #0338 [older| permalink|newer] / ↑Entrée #0338 [précédente| permalien|suivante] ↑

[Index of all entries / Index de toutes les entréesLatest entries / Dernières entréesXML (RSS 1.0) • Recent comments / Commentaires récents]