@ for dot productrequests APIrequests is pleasant HTTP client library. It's great but it would be awesome if it was asynchronous (but could it be pleasant and asynchronous at the same time?). The examples below are from Kenneth Reitz, the author of requests (source).
requestsimport requests
r = requests.get('https://api.github.com', auth=('user', 'pass'))
print r.status_code
print r.headers['content-type']
# ------
# 200
# 'application/json'
urllib2import urllib2
gh_url = 'https://api.github.com'
req = urllib2.Request(gh_url)
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_manager.add_password(None, gh_url, 'user', 'pass')
auth_manager = urllib2.HTTPBasicAuthHandler(password_manager)
opener = urllib2.build_opener(auth_manager)
urllib2.install_opener(opener)
handler = urllib2.urlopen(req)
print handler.getcode()
print handler.headers.getheader('content-type')
# ------
# 200
# 'application/json'
In [19]:
s = 'Fluent'
L = [10, 20, 30, 40, 50]
print(list(s)) # list constructor iterates over its argument
a, b, *middle, c = L # tuple unpacking iterates over right side
print((a, b, c))
for i in L:
print(i, end=' ')
In [3]:
len(s), len(L)
Out[3]:
In [4]:
s.__len__(), L.__len__()
Out[4]:
In [10]:
a = 2
b = 3
a * b, a.__mul__(b)
Out[10]:
In [24]:
L = [1, 2, 3]
L.append(L)
L
Out[24]:
In [27]:
x = 2**.5
x
Out[27]:
In [29]:
format(x, '.3f')
Out[29]:
In [31]:
from datetime import datetime
agora = datetime.now()
print(agora)
print(format(agora, '%H:%M'))
In [34]:
'{1:%H}... {0:.3f}!'.format(x, agora)
Out[34]:
In [ ]: