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.

10 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. 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
  3. I have completely read your post and the content is crisp and clear. Thank you for posting such an informative article, I have decided to follow your blog so that I can myself updated. Python Training in Chennai

    ReplyDelete
  4. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...Python Online Training Hyderabad

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it. Python Training in Chennai

    ReplyDelete
  7. Really Good blog post.provided a helpful information.I hope that you will post more updates like this Python Online Training Hyderabad

    ReplyDelete
  8. Thanks for the efforts on gathering python useful content and sharing here.Python Online Training Hyderabad

    ReplyDelete