Wednesday, June 8, 2016

imports of no import

The Python standard library has hundreds of built-in modules (mine has 688 by one count). Some are more useful than others.

The most famous is "import this", which prints out the Zen of Python. The next most popular fun module could well be antigravity. Try importing it on a browser-capable machine, and (spoiler), you'll be taken here.

And Randall is right. As most people know, Python's "Hello world" is just one line: "print 'Hello world'"

But what if there were another, more confusing way to do it? Taking a page out of ow about:

>>> import __hello__
"Hello world..."

And, because it's a one-time module import, this super-useful module only works the one time:

>>> import __hello__
>>>

It even breaks that behavior on Python 3:

>>> import __hello__
"Hello world!"

And if that wasn't esoteric enough of an import, how about even more new syntax in Python 3:

>>> from __future__ import barry_as_FLUFL
>>> 'a' <> 'b'
True
>>> 'a' <> 'a'
False
 
This unfortunate syntax is the result of an April Fools PEP from 2009. Before this, previous attempts at introducing new syntax were met with a stiffer upper lip:

>>> from __future__ import braces
  File "<stdin>", line 1
SyntaxError: not a chance


All of which raises the question: how many undocumented jokes have made their way into Python?

Mahmoud
https://github.com/mahmoud
https://twitter.com/mhashemi

Credit to Python core dev Raymond Hettinger and other Twitter friends for details and inspiration.

9 comments:

  1. Excellent post, I agree with you 100%! I’m always scouring the Internet for new information and learning whatever I can, and in doing so I sometimes leave comments on blogs. Website Designing Bangalore | Web Design Companies Bangalore

    ReplyDelete
  2. Really an awesome post. I wondered by reading this blog post. Thanks a lot for posting this unique post which you have shared with us. Keep on posting like this exclusive post with us.

    Seo Company in Chennai

    ReplyDelete
  3. Cool post, thanks. Speaking about online technologies. I suggest to keep your paperwork stored online. Read about dataroom software and everything will be clear.

    ReplyDelete
  4. Truly an Outstanding post.I reading this blog post it's amazing. We post this blog post is very unique and it's that share with us. We share this post is very exclusive.
    SEO Training in Chennai | Digital Marketing Training in Chennai

    ReplyDelete
  5. Great post..,Talking about the python technologies.i really happy to read your blog. keep sharing more blogs.
    Thanks for sharing.


    Python Online Training

    ReplyDelete
  6. hello everyone.....
    thank the good topic.
    Welcome To Casino online Please Click the website
    thank you
    baccarat
    บาคาร่า
    จีคลับ

    ReplyDelete
  7. Nice blog. The person does not have programming knowledge. This blog can help me to analyses the blog nature. Thanks for sharing.


    Python Online Training

    ReplyDelete
  8. thanks for sharing.for more information : click here

    ReplyDelete