[Python-de] Re: Funktion ueberschreiben?

[email protected] (Stefan Ram)
Newsgroups gmane.comp.python.general.german
Organization Stefan Ram
Message-ID <[email protected]>
=?UTF-8?Q?Mike_M=c3=bcller?= <[email protected]> writes:
>import duplicity.dup_time
>def timetopretty(timeinseconds):
>     """Return pretty version of time"""
>     return time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(timeinseconds))
>duplicity.dup_time.timetopretty = timetopretty
>ganz zu Beginn des Programms sollte funktionieren. Wichtig ist, dass
>duplicity.dup_time nicht schon vorher importiert wird. Sonst müsstest du es
>vorher aus sys.modules entfernen.

  Diese Einschränkung verstehe ich nicht ganz. Ich dachte, daß sich
  das "monkey patching" ab dem Zeitpunkt seiner Ausführung auswirkt.
  In Deinem Beispiel wird doch auch "schon vorher importiert", also
  als erstes importiert, dann gepatcht, und ab da wirkt es. Vergleiche:

import tkinter.messagebox
tkinter.messagebox.showinfo( "arg", "arg1" )
tkinter.messagebox.showinfo = print
tkinter.messagebox.showinfo( "arg", "arg1"  )

  .

_______________________________________________
python-de Mailingliste -- [email protected]
Zur Abmeldung von dieser Mailingliste senden Sie eine Nachricht an [email protected]
https://mail.python.org/mailman3/lists/python-de.python.org/
Mitgliedsadresse: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.