$ python3 -c "import this"
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
is_user_install_anything_useful = False
try:
import django
is_user_install_anything_useful = True
except ImportError:
pass
try:
import sqlalchemy
is_user_install_anything_useful = True
except ImportError:
pass
if not is_user_import_anything_useful:
raise ImportError('Install django or SQLalchemy')
In [1]: for counter in range(1, 11):
...: print(".//*[@id='b_results']/li[{}]/div[2]/div/cite".format(counter))
...:
.//*[@id='b_results']/li[1]/div[2]/div/cite
.//*[@id='b_results']/li[2]/div[2]/div/cite
.//*[@id='b_results']/li[3]/div[2]/div/cite
.//*[@id='b_results']/li[4]/div[2]/div/cite
.//*[@id='b_results']/li[5]/div[2]/div/cite
.//*[@id='b_results']/li[6]/div[2]/div/cite
.//*[@id='b_results']/li[7]/div[2]/div/cite
.//*[@id='b_results']/li[8]/div[2]/div/cite
.//*[@id='b_results']/li[9]/div[2]/div/cite
.//*[@id='b_results']/li[10]/div[2]/div/cite
>>> import lxml.html
>>> html = lxml.html.fromstring('''\
... <html><body onload="" color="white">
... <p>Hi !</p>
... </body></html>
... ''')
>>> print lxml.html.tostring(html)
<html><body onload="" color="white"><p>Hi !</p></body></html>
>>> print lxml.html.tostring(html)
<html> <body color="white" onload=""> <p>Hi !</p> </body> </html>
>>> print lxml.html.tostring(html)
<html>
<body color="white" onload="">
<p>Hi !</p>
</body>
</html>
print(urllib.request.urlopen("http://ex.ua").read().decode('utf-8'))
import requests
requests.get('http://ex.ua').text
sudo pip install Cython==0.17.1
In [3]: from json import loads
In [4]: print(loads('{"success":true,"result":"ok"}'))
{'result': 'ok', 'success': True}
In [5]: print(type(loads('{"success":true,"result":"ok"}')))
<class 'dict'>
try:
x = 1/0
except ZeroDivisionError:
print("Try in another world")