Move to Python 3!
Graham Markall - @gmarkall
Ian Ozsvald - @ianozsvald, ianozsvald.com
Graham Markall - @gmarkall
Ian Ozsvald - @ianozsvald, ianozsvald.com
An (incomplete) list:
async
/await
, fine-grained OSError
subclasses,
yield from
, fault handlers, unorderable types, type hints, iterators
everywhere...Brief demos of:
@
operator@
operatorOld "syntax":
M.dot(M.T).dot(N.dot(v))
New syntax:
M @ M.T @ N @ v
Defining matrix multiplication for your own classes:
def __matmul__(self, other) # @
def __rmatmul__(self, other) # @
def __imatmul__(self, other) # @=
Get "everything else" from an iterable:
>>> a, b, *rest = range(10)
>>> a
0
>>> b
1
>>> rest
[2, 3, 4, 5, 6, 7, 8, 9]
Get the first and last lines of a file:
>>> with open('using_python_to_profit.txt') as f:
first, *_, last = f.readlines()
>>> first
'Step 1: Use Python 3\n'
>>> last
'Step 10: Profit!\n'
def cleanup(folder, *, extreme=False):
if extreme:
shutil.rmtree('/')
else:
shutil.rmtree(folder)
>>> cleanup('/home/gmarkall/tmp', '/home/gmarkall/tmp2')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cleanup() takes 1 positional argument but 2 were given
“Ubuntu 15.10 (Wily Werewolf) to Switch to Python 3.5 Ahead of Ubuntu 16.04 LTS”
conda create -n py34 python=3.4 anaconda