开发者

Python interactive interpreter in hashbang line

For my django projects, I wanted to write a simple replacement for manage.py shell to take advantage of bpython. Essentially all it does is run setup_environ(settings) and then import some common models (User, etc.)

in any case, everything works fine when I run bpython -i bshell.py (my script is named bshell.py). Then I thought I'd get clever and set the hashbang line to #!/usr/bin/env bpython -i to make it even simpler, and this worked on the OSX but is not working now in Ubuntu (10.10).

#!/usr/bin/env python -i also does not work, but #!/usr/bin/env bpython works (开发者_JAVA技巧but obviously doesn't drop into the interactive prompt).

It's a small point, but over the course of my life it will save me hundreds of "bpython -i"s if I can just run my script as ./bshell.py (really I'm just curious). Any ideas why it's not working on Ubuntu?

I should note I'm in a virtualenv, and I already double checked that line endings are *nix style.


From wikipedia:

Another portability problem is the interpretation of the command arguments. 
Some systems, including Linux, do not split up the arguments; for example, 
when running the script with the first line like,

#!/usr/bin/env python -c

That is, python -c will be passed as one argument to /usr/bin/env, 
rather than two arguments.

If it's no big deal, you're probably better off using the actual path to bpython instead of going through /usr/bin/env.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜