### An annoying thing with Python slices

You of course know that Python slices are awesome:

```a = 'ABCDEFG'
a[:3] -> 'ABC'
a[2:5] -> 'CDE'
```

And more interestingly:

```a[-3:] -> 'EFG'
```

and

```a[6:4:-1] -> 'GF'
```

But you can see that the reverse slicing is starting to stretch the fence-post we are familiar with. Python uses zero based, inclusive-exclusive indexing. This corresponds to a C syntax of `(for i = n; i < m; i++)`. When you reverse it the slice goes `(for i = m - 1; i > n - 1; i--)`.

As you can imagine this starts to get ugly and at one point it gets to be wrong:

Say, as is often the case, you are not taking static, pre-determined slices but rather slices determined at runtime. Say you are taking slices between `n` and `m` or `[n, m)`.

The forward slice is `a[n:m]`
The backward slice is `a[m-1:n-1:-1]` right? Because of the fence posts?

Well yes, except what happens when `n = 0`? The forward slice is fine but the reverse slice resolves to `a[m-1:-1:-1]`

This is where Python becomes a little too clever. As you will recall from our earlier examples, negative indices indicate offsets from the end of the object. So, the last slice returns empty.

The correct slice is `a[m-1:None:-1]` or `a[m-1::-1]` and the logic for this is cumbersome:

`a[m-1:n-1 if n > 0 else None:-1]`

The simpler way is to do `a[n:m][::-1]`.

### Python: Multiprocessing: passing multiple arguments to a function

Write a wrapper function to unpack the arguments before calling the real function. Lambda won't work, for some strange un-Pythonic reason.

import multiprocessing as mp def myfun(a,b): print a + b def mf_wrap(args): return myfun(*args) p = mp.Pool(4) fl = [(a,b) for a in range(3) for b in range(2)] #mf_wrap = lambda args: myfun(*args) -> this sucker, though more pythonic and compact, won't work p.map(mf_wrap, fl)

### Flowing text in inkscape (Poster making)

You can flow text into arbitrary shapes in inkscape. (From a hint here).

You simply create a text box, type your text into it, create a frame with some drawing tool, select both the text box and the frame (click and shift) and then go to text->flow into frame.

UPDATE: