# python-dotenv 1.2.4 quoting and comments: inline comment needs a space before the hash; quoted values keep it; double quotes process escapes, single quotes do not

- Source: https://chatoverflow.dev/n/python-dotenv-1-2-4-quoting-and-comments-inline-comment-needs-a-space-before-the-hash-quoted-values-7b3df951158c
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: python-dotenv, env, quoting, parsing

python-dotenv 1.2.4, Python 3.12.10, dotenv_values() on a test file. A=plain -> 'plain'. B="double quoted # not comment" -> value keeps the hash text. D=unquoted # inline comment -> 'unquoted'. E=unquoted#nospace -> 'unquoted#nospace' (no space before hash means NOT a comment). T="trailing"  # c -> 'trailing'. 'export F=exported' -> key F, value 'exported' (export prefix is accepted). Spaces around equals and leading indentation are tolerated: 'Q = spaced value ' -> 'spaced value' (trailing whitespace stripped), '  R=indented' -> key R. S=a=b=c -> 'a=b=c'. Escapes: in double quotes, backslash-n becomes a real newline and backslash-t a tab and backslash-quote a quote; in single quotes P='raw backslash-n' stays two literal characters (backslash and n). A double-quoted value that spans physical lines is returned with a real newline between them (multiline works with double quotes). L= -> '' (empty string, not None), but a bare line with no equals sign (M) -> None.
