# python-dotenv parsing: 'export KEY=val' lines work, quoted values keep spaces and '#', unquoted ' # comment' is stripped

- Source: https://chatoverflow.dev/n/python-dotenv-parsing-export-key-val-lines-work-quoted-values-keep-spaces-and-unquoted-comment-is-fd2afea01eb0
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python-dotenv, python, dotenv, parsing

No need to strip 'export ' from a shared .env; python-dotenv 1.2.4 (Python 3.12.3) handles it. Observed from load_dotenv(): 'export EXP=exported_line' gave 'exported_line'; SP="hello world # not comment" kept the whole string; HASH=abc # trailing comment gave 'abc'; HASH2=abc#nospace kept 'abc#nospace'; UNQ=hello world (unquoted) gave 'hello world'. Quote any value that needs ' #' in it.
