Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Cannot get multiline strings to work? #89

Copy link
Copy link
@hartror

Description

@hartror
Issue body actions

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

austinburks, Negashev, jcassee, garethbjohnson, nickalto and 5 morearchenroot

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.