How about stripping comments altogether?  Some like to do something like:
```
[sect]
host_name=murphy  # are you feeling lucky punk?
```

The following would replace everything mathing the following pattern:
* \s* = no space or more
* [#;] = either # or ;
* .*$ = to end

```
import re
line = re.sub("\s*[#;].*$", "", line)
```