Share your repls and programming experiences

← Back to all posts
Python Easter Egg
h
RogueHalo (404)

Not many people actually know about this easter egg in python.

By typing import this into either a python interpreter or a python shell you can be presented with Tim Peters' 20 aphorisms Guiding principles for writing Python, however, he only wrote down 19, why? I don't know.

Anyway, I'll leave you with that, if you know of any more easter eggs, leave a comment with it!

Have a great Day!

Commentshotnewtop
Highwayman (1305)

Try
from __future__ import braces

Highwayman (1305)

@tobyyhsieh thanks!

I hadn’t noticed it had so many upvotes cool.

[deleted]

@Highwayman
import this
import antigravity
import __hello__

>>> import this
...
>>> love = this
>>> this is love
True
>>> love is True
False
>>> love is False
False
>>> love is not True or False
True
>>> love is not True or False; love is love  # FML
True

the this.py moudule is:

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]))
>>> infinity = float('infinity')
>>> hash(infinity)
314159
>>> hash(float('-inf'))
>>> from antigravity import geohash
>>> # Your location, a date and that date's (or most recent) DJIA opening.
>>> geohash(37.421542, -122.085589, b'2005-05-26-10458.68')
37.857713 -122.544543
>>> from math import pi
>>> π = pi
>>> area = π * r**2

>>> résumé = 'knows Python'
>>> 'Python' in résumé
True
Highwayman (1305)

@TaylorLiang

'Python' in résumé

my favorite that was good lol.

SixBeeps (2311)

@TaylorLiang

import antigravity

is that an xkcd reference? lol

EDIT: It definitely is

[deleted]

@niorg2606 I think so

[deleted]

@niorg2606 if your run it on your own computer (like the python interpriter) it opens up that comic

AtticusKuhn (236)

This is my personal favorite thing to do in my limited knowledge of python

[deleted]

nice

Flux3on (11)

Never have I enjoyed 11 bytes of code more.

Highwayman (1305)

I had forgotten about that..

RobertFurr (43)

from future import braces

PowerCoder (557)

Oh! I've heard about this. Cool! (I never actually tried it.)

PVWalsh (2)

waaaaaaaaaaaa????????????????????

nathancoder (1)

you can also use
import that

KhoiXuanXuan (0)

import antigravity will do some stuff.

eaz (8)

ah yes, the fabled zen of python
the secret 20th part is xkcd.com, because import antigravity makes xkcd canonically part of the python stdlib

RogueHalo (404)

@eaz Ah, thanks for that, I never knew that.

AugnivMitra (0)

Also, typing import that You can see The Anti-Zen of Python

leFrank (1)

import that typed in adds more poems

ChoppaFan2007 (13)

wow this sure is a cool post! i love it! but i love my choppa more

ThePhoenixfish (42)

Import that also worked to give the ant zen!
:D

JoelMenezes (11)

@JacksonCowie have you tried import that ?

RogueHalo (404)

@JoelMenezes Yeah That one is good as well!

MartiCliment (0)

it seems to also work with:
impot that

--or, in CMD:

pip install that
import that