This package tries to overcome some of the issues with copying code examples from various sources such as pdf files where there are likely to be line numbers, the Python REPL, where prompts confuse things, or iPython where numbered prompts are an issue.
You can install with:
pip install clipfix