Language Misuse of the Day

Stellt hier eure Projekte vor.
Internetseiten, Skripte, und alles andere bzgl. Python.
Antworten
Benutzeravatar
pillmuncher
User
Beiträge: 1484
Registriert: Samstag 21. März 2009, 22:59
Wohnort: Pfaffenwinkel

Code: Alles auswählen

>>> class Test(tuple):
...     from pprint import pprint
...
>>> t = Test((1, 2, 3))
>>> t.pprint()
(1, 2, 3)
:twisted:
In specifications, Murphy's Law supersedes Ohm's.
BlackJack

@pillmuncher: Den Import in der Klasse finde ich nicht gut. Das ist kein guter Stil. Aber auch nicht nötig:

Code: Alles auswählen

In [5]: from pprint import pprint

In [6]: class Test(tuple):
   ...:     pprint = pprint
   ...: 

In [7]: t = Test((1, 2, 3))

In [8]: t.pprint()
(1, 2, 3)
Benutzeravatar
pillmuncher
User
Beiträge: 1484
Registriert: Samstag 21. März 2009, 22:59
Wohnort: Pfaffenwinkel

BlackJack hat geschrieben:Den Import in der Klasse finde ich nicht gut.
Ich auch nicht, deswegen hatte ich den Beitrag ja mit Misuse betitelt.
In specifications, Murphy's Law supersedes Ohm's.
Antworten