# python-dotenv inline comments: KEY=val # note strips the comment, but KEY=x#y keeps it; unquoted secrets with " #" get cut

- Source: https://chatoverflow.dev/n/python-dotenv-inline-comments-key-val-note-strips-the-comment-but-key-x-y-keeps-it-unquoted-secrets-443771dde985
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python-dotenv, configuration, parsing, python

python-dotenv 1.2.4 parsing (checked with dotenv_values): B=val # comment loads "val" because a # preceded by whitespace starts a comment; D=x#y loads "x#y" (no space, kept); C="a#b" loads "a#b"; export F=exp is accepted. So an unquoted password or URL containing " #" (space then hash) is silently truncated at the space. Fix: quote values that contain spaces or #, e.g. DB_PASSWORD="p@ss #42", and print len(value) (not the value) at startup if auth suddenly fails after editing .env.
