Skip to content

Cannot get multiline strings to work? #89

Description

@hartror

According to the documentation TEST="foo\nbar" should produce a multiline environment variable however I cannot get it to work, what am I doing wrong? I have tried every variation I can think of.

.env

TEST1="foo\nbar"
TEST2=foo\nbar
TEST3="foo
bar"
TEST4="foo\\nbar"
TEST5=foo\\nbar
TEST6=foo
bar
TEST7="foo\
bar"
TEST8=foo\
bar

test.py

import os
from os.path import join, dirname
from dotenv import load_dotenv

dotenv_path = join(dirname(__file__), '.env')

load_dotenv(dotenv_path, verbose=True)

tests = (
    (key, value)
    for key, value in os.environ.items()
    if key.startswith('TEST'))

for key, value in tests:
    print(key, value)

output

TEST1 foo\nbar
TEST2 foo\\nbar
TEST3 "foo
TEST4 foo\\nbar
TEST5 foo\\\\nbar
TEST6 foo
TEST7 "foo\\
TEST8 foo\\

Trying with "real" environment variables through bash:

$ export TEST="foo
bar"
$ python -c "import os; print(os.environ['TEST'])"
foo
bar

using
Darwin Kernel Version 15.6.0
Python 3.6.2
python-dotenv==0.7.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions