Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
796 connectés 

  FORUM HardWare.fr
  Programmation
  Python

  Le Zen du Python

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Le Zen du Python

n°282688
Kristoph
Posté le 09-01-2003 à 16:56:08  profilanswer
 

C'est marrant, je viens de trouver cet "Easter Egg" dans Python ( version 2.2 minimum parait-il ).
 
Faites "import this" et vous obtenez ça :
 

Code :
  1. >>> import this
  2. The Zen of Python, by Tim Peters
  3. Beautiful is better than ugly.
  4. Explicit is better than implicit.
  5. Simple is better than complex.
  6. Complex is better than complicated.
  7. Flat is better than nested.
  8. Sparse is better than dense.
  9. Readability counts.
  10. Special cases aren't special enough to break the rules.
  11. Although practicality beats purity.
  12. Errors should never pass silently.
  13. Unless explicitly silenced.
  14. In the face of ambiguity, refuse the temptation to guess.
  15. There should be one-- and preferably only one --obvious way to do it.
  16. Although that way may not be obvious at first unless you're Dutch.
  17. Now is better than never.
  18. Although never is often better than *right* now.
  19. If the implementation is hard to explain, it's a bad idea.
  20. If the implementation is easy to explain, it may be a good idea.
  21. Namespaces are one honking great idea -- let's do more of those!


 
;)

mood
Publicité
Posté le 09-01-2003 à 16:56:08  profilanswer
 

n°282702
lorill
Posté le 09-01-2003 à 17:03:16  profilanswer
 

le truc gore c'est que c'est codé en dur dans l'interpreteur [:vomi]
alors qu'il aurait été si simple de créer un module qui fait un print du texte


Message édité par lorill le 09-01-2003 à 17:07:26
n°282722
Taz
bisounours-codeur
Posté le 09-01-2003 à 17:15:39  profilanswer
 

c'est bien plus marrant comme ça
 

s = """Gur Mra bs Clguba, ol Gvz Crgref
 
Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf orggre guna pbzcyvpngrq.
Syng vf orggre guna arfgrq.
Fcnefr vf orggre guna qrafr.
Ernqnovyvgl pbhagf.
Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.
Nygubhtu cenpgvpnyvgl orngf chevgl.
Reebef fubhyq arire cnff fvyragyl.
Hayrff rkcyvpvgyl fvyraprq.
Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.
Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg.
Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu.
Abj vf orggre guna arire.
Nygubhtu arire vf bsgra orggre guna *evtug* abj.
Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.
Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.
Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr!"""
 
d = {}
for c in (65, 97):
    for i in range(26):
        d[chr(i+c)] = chr((i+13) % 26 + c)
 
print "".join([d.get(c, c) for c in s])


Message édité par Taz le 09-01-2003 à 17:16:00
n°282755
Kristoph
Posté le 09-01-2003 à 17:50:41  profilanswer
 

Un ROT13 en 4 lignes, pas mal :)

n°282811
Kristoph
Posté le 09-01-2003 à 18:18:41  profilanswer
 

Et comme ca ?
 

Code :
  1. >>> import string
  2. >>> text = """ Ici le texte """
  3. >>> s = "abcdefghijklmnopqrstuvwxyz"
  4. >>> d = s[13:]+s[:13]
  5. >>> t = maketrans(m+m.upper(),d+d.upper())
  6. >>> text.translate(t)
  7. ' Vpv yr grkgr '


n°282828
lorill
Posté le 09-01-2003 à 18:26:59  profilanswer
 

Kristoph a écrit :

Et comme ca ?
 

Code :
  1. >>> import string
  2. >>> text = """ Ici le texte """
  3. >>> s = "abcdefghijklmnopqrstuvwxyz"
  4. >>> d = s[13:]+s[:13]
  5. >>> t = maketrans(m+m.upper(),d+d.upper())
  6. >>> text.translate(t)
  7. ' Vpv yr grkgr '


 


mouaif :/
 
en ruby :

Code :
  1. text = "ici le texte"
  2. puts text.tr("a-mn-z", "n-za-m" )


Message édité par lorill le 09-01-2003 à 18:29:32
n°282831
Taz
bisounours-codeur
Posté le 09-01-2003 à 18:30:21  profilanswer
 

ouais, ben évidemment, si tu veux te la jouer au langage qui à la bibliotheque standard la plus grosse  :o

n°282836
Kristoph
Posté le 09-01-2003 à 18:39:32  profilanswer
 

Et comme ça ?
 

Code :
  1. text = "texte"
  2. print text.decode('rot13')


 
http://mail.python.org/pipermail/p [...] 07895.html


Message édité par Kristoph le 09-01-2003 à 18:41:24
n°282840
lorill
Posté le 09-01-2003 à 18:43:48  profilanswer
 

Kristoph a écrit :


print text.decode('rot13';)


ils ont osé [:totoz]
au fait et cette histoire de booléens, ca donne quoi ?
quand j'ai arreté de suivre ils étaient en train de s'étriper a ce sujet...

n°282852
Kristoph
Posté le 09-01-2003 à 18:54:26  profilanswer
 

Comment ça ? Un rapport avec la discussion pour savoir s'il fallait integrer oui ou non les boolean dans le langage ? J'ai pas suivi non plus.


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Python

  Le Zen du Python

 

Sujets relatifs
Scirpts FTP en pythonmon petit cours de python
Java Python Extension => comment obtenir libpythonXX.so ?Est il possible de compiler du python ?
Un bon tutorial en pythonPourquoi Python ? L'avis de Bruce Eckel
probleme de changement de type pour une variable [newbies du Python][python] y a-t-il un moyen de compiler...
[Python] Connection a une DB MySQLDebuts en Python
Plus de sujets relatifs à : Le Zen du Python


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR