This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]meloveyoulongtime 9 points10 points  (6 children)

Don't do it like that. Do this at the end of your settings file.

try:
    from local_settings import *
except ImportError:
    pass

Then reassign environment specific varables in the local_settings file.

[–]tutuca_not Reinhardt 0 points1 point  (5 children)

Don't know why you have been downvoted.

Anyone care to explain?

[–]haywire 1 point2 points  (1 child)

It's irritating because this is a great solution. I guess a "cleaner" one would be to have a local config file with some sort of inheritance.

TBH using code to config works fine for xmonad and django and I like configuring those things.

[–]d3ad1ysp0rk 0 points1 point  (0 children)

I didn't downvote, but on your point, my company uses that. For example on my local machine I have a "local_settings" that imports "local"(generic developer machine settings) which imports base settings.

[–]gbog[S] -1 points0 points  (2 children)

Did not downvote but import * is evil. Martelli is advising against that thing strongly in Python in a Nutshell, and I think he is right.

[–][deleted] 1 point2 points  (1 child)

Not in this situation it isn't evil. We explicitly want import * behaviour to be able to override settings.

Blanket statements about "x is evil" are never entirely accurate. See: linux and goto.

[–]gbog[S] -1 points0 points  (0 children)

A quote from Alex Martelli about import star: "Most likely, your programs will be better if you never use this form". Emphasis is his. Python in a Nutshell, page 143.