Ok... this is *really* the last time.

I don't know why I was using a regular expression, when string.replace
would have done just as well. Here's my final version of the external
method. I *promise* I won't change it again.

Of course, the simplest version would be

from string import replace
def D_date(datestring):
     datestring=replace(datestring, 'Monday', 'Montag')
     datestring=replace(datestring, 'Tuesday', 'Dienstag')
     # und so weiter

However, this would be slower to execute than using "reduce", as below.

----
from string import replace

# you can remove lines where the words are the same in both languages
replacements={
    'Monday':'Montag',
    'Tuesday':'Dienstag',
    'Wednesday':'Mittwoch',
    'Thursday':'Donnerstag',
    'Friday':'Freitag',
    'Saturday':'Samstag',
    'Sunday':'Sonntag',
    'January':'Januar',
    'February':'Februar',
    'March':'März',
    'April':'April',
    'May':'Mai',
    'June':'Juni',
    'July':'Juli',
    'August':'Augustus',
    'September':'September',
    'October':'Oktober',
    'November':'November',
    'December':'Dezember'
    }

replace_fns=[]
for e,d in replacements.items():
    replace_fns.append(
        eval("lambda x: replace(x, '%s', '%s')" % (e, d)))
del replacements

def D_date(datestring):
    return reduce(lambda x,y: y(x), replace_fns, datestring)

----

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net

_______________________________________________
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )

Reply via email to