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.

8 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. Thank you for providing us with this useful information. Every time I read it, your tips help me work more efficiently and quietly. In my spare time, I enjoy reading your blog posts and learning new things from them like I learn from Pay Someone To Take A Class For You. I'd like to thank you for all of your work. This is an excellent attempt.

    ReplyDelete
  4. Take advantage of Casinority, your perfect guide for successful real money gambling https://casinority.com/au/pokies/. Casinority offers listings of the best casino sites for dozens of countries, along with reviews on slots and games. Play like an expert and win mind-blowing prizes by following our advice on bonuses, free spins, casino games, loyalty rewards, playing strategies, and more.

    ReplyDelete
  5. Fly in your business advisor london. Enter your 16-digit top-up voucher code close by a few private information. Vouchers can be bought from any spot you see these logos:.

    ReplyDelete
  6. Thanks for the nice article. It was extremely helpful for me. I am happy that I found this blog. You can also visit our site https://rootcasino-rs.com/ . And you will be able to learn much more than you imagine

    ReplyDelete