过度使用 sitecustomize.py: .bash_profile 代替?
也许是因为我更喜欢 python 而不是 shell,但我选择添加到 /usr/lib/python[xx]/sitecustomize.py
中的 sys.path
列表code> 以这种方式:
base = '/home/droogans/py/'
locs = ['foo','django']
for loc in locs:
sys.path.insert(0, base + loc)
现在我在其下面添加了一个 try: except
块,以防我想在不使用 python manage.py shell
方法。
try:
from django.core.management import setup_environ
from website_foobar import settings
setup_environ(settings)
except ImportError:
pass
DjangoBook 有一个部分,“特殊的 python 提示”,建议您这样做,但建议使用 .bash_profile
shell 脚本来执行该任务。使用它代替 sitecustomize.py
脚本是否有可衡量的好处?显然,我已经完成了,所以必须有某种令人信服的证据才能让我在谷歌上搜索一篇关于编写 shell 代码的文章。
Maybe it's because I am more comfortable with python over the shell, but I chose to add to my sys.path
list in /usr/lib/python[x.x]/sitecustomize.py
in this manner:
base = '/home/droogans/py/'
locs = ['foo','django']
for loc in locs:
sys.path.insert(0, base + loc)
And now I've added a try:except
block below it, in case I want to test out a template without using the python manage.py shell
approach.
try:
from django.core.management import setup_environ
from website_foobar import settings
setup_environ(settings)
except ImportError:
pass
The DjangoBook has a section, "A special python prompt", that recommends you do this, but suggests using your .bash_profile
shell script for the task. Is there a measurable benefit to utilizing that instead of a sitecustomize.py
script? Obviously, I'm already done, so there'll have to be some kind of compelling evidence for me to google an article on writing shell code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有时您在所使用的计算机上不会拥有超级用户状态。在这种情况下,您将无法修改
/usr
,因此有必要知道如何在您的个人 ~/.bashrc 或 ~/.profile 或 ~/.bashrc 中设置环境变量。 bash_配置文件。 (要使用的特定文件取决于您的系统)。这并不难做到。您需要添加的只是(我认为!)
Sometimes you are not going to have superuser status on the machine you are using. In such cases you won't be able to modify
/usr
, so it would be necessary then to know how to set environment variables in your personal ~/.bashrc or ~/.profile or ~/.bash_profile. (The particular file to use depends on your system).It's not hard to do. All you'd need to add (I think!) is something like