why not just strip lines beforehand?  e.g.

```code = [line.strip() for line in code]```