Voilà, c'est mon premier programme en Python. Il provient de la revue 'Linux Journal', juillet 2005, p.20. Lorsque je fais rouler le programme, le message suivant s'affiche: 'no module named datetime'.
Je travaille en Linux RedHat 8.0. Le package mx-2.0.3-6.rpm était déjà installé. J'ai désinstallé le tout, réinstallé le package egenix-mx-base-2.0.6-py2.2_1.i386.rpm et l'erreur persiste toujours.
Où est l'erreur?
Voici le programme:
#!/usr/bin/python
# Grab the CGI module
import cgi
import psycopg
import icalendar
from iCalendar import Calendar, Event
from mx.DateTime import datetime
from iCalendar import UTC # timezone
# Log any problems that we might have
import cgitb
cgitb.enable(display=0, logdir="/tmp")
# Send a content-type header
print "Content-type: text/calendar\n\n"
# Create a calendar object
cal = Calendar()
# What product created the calendar?
cal.add('prodid','-//Python iCalendar 0.9.3//mxm.dk//')
# Version 2.0 correspond to RFC 2445
cal.add('version', '2.0')
# Create the database connection
db_connection = psycopg.connect('dbname=calendar user=postgres')
db_cursor = db_connection.cursor()
db_cursor.execute ('''SELECT
event_id, event_summary, event_location,
event_start, event_end, event_timestamp
FROM Events
ORDER BY event_start''')
result_rows = db_cursor.fetchall()
for row in result_rows:
# Create one event
event = Event()
# Set the event ID
event['uid'] = str(row[0]) + 'id@ATF'
# Set the description and location
event.add('summary', row[1])
event.add('location', row[2])
# Transform the dates appropriately
event.add('dtstart', datetime(tzinfo=UTC(), *row[3].tuple()[0:5]))
event.add('dtend', datetime(tzinfo=UTC(), *row[4].tuple()[0:5]))
event.add('dtstamp', datetime(tzinfo=UTC(), *row[5].tuple()[0:5]))
# Give this very high priority!
event.add('priority', 5)
# Add the event to the calendar
cal.add_component(event)
# Ask the calendar to render itself as an iCalendar
# file, and return that file in an HTTP response
print cal.as_string()
Si quelqu'un peut m'aider, ce sera apprécié!
Merci