I'm wondering if it might be better to completely strip the comments here with a regexp no matter where they occur on the line?  That would seem more flexible.

My concern, however, is if a person has an equal sign in the comment that the other regexp may fail if comments are not stripped here.  For example, `MY_KEY = MY_VALUE  # used to = MY_OLD_VALUE` would assign `MY_VALUE  # used to = MY_OLD_VALUE` as the value of MY_KEY if you don't strip all the comments here.

Also, this will not catch a comment with a leading space... so this: `[space(s)] # MY_KEY=MY_VALUE` will assign `MY_KEY=MY_VALUE` with the current code.

See my regexp example above if you don't want to fully strip comments here.