rewrite captureN using python