0

I'm learning Django, so be gentle with me.

I have this code here, in my Settings.py-file:

STATICFILES_DIRS = (
        os.path.join(BASE_DIR, "static"),
        )

print("STATICFILES_DIRS ", STATICFILES_DIRS[0] )
print("STATICFILES_DIRS ", STATICFILES_DIRS )

I don't understand the result, which is this:

STATICFILES_DIRS C:\path\to\static\folder
STATICFILES_DIRS ('C:\\path\\to\\static\\folder',)

Why do the double-backslashes appear, when I print the tuple? Is it because it's 'escaping-the-next-character'?

3
  • 1
    yes, you got it... it is escaping the next character Commented Aug 13, 2015 at 18:42
  • "I'm learning Django...". This question has got nothing to do with Django. Commented Aug 13, 2015 at 19:09
  • Xyres - please evaluate your answer. I'm setting this up in my Django-settings.py-file? How else should I address this? Commented Aug 15, 2015 at 18:37

1 Answer 1

1

This probably is a manifold over duplicate question, but:

Python escaping routines. Python uses a backslash as standard escape in string representation. Which is exactly what happens here.

To give some easy (documented) examples:

Escape Sequence     Meaning 
\newline            Ignored
\\  Backslash       (\)
\'  Single quote    (')
\"  Double quote    (")

You can see the difference through an example like this:

>>> spam_eggs = '''spam
... eggs'''
>>> print spam_eggs
spam
eggs
>>> print repr(spam_eggs)
'spam\neggs'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.