469,328 Members | 1,266 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,328 developers. It's quick & easy.

Can i use this script as a python evaluator?


<code>
#! /bin/sh
python -c "import sys;exec(sys.stdin)"
</code>

Emacs has a function `shell-command-on-region', which takes region as
input for the evaluator (script above), and output its result. I have
tried and found it works, is there any problems for this, or any other
better solution for it? Thanks.
Oct 20 '08 #1
4 1153
Bruno Desthuilliers <bd*****************@free.quelquepart.frwrites:
Peter Wang a écrit :
><code>
#! /bin/sh
python -c "import sys;exec(sys.stdin)"
</code>

Emacs has a function `shell-command-on-region', which takes region as
input for the evaluator (script above), and output its result. I have
tried and found it works, is there any problems for this, or any other
better solution for it? Thanks.
If your problem is to eval a region of a python buffer and output the
result to another buffer, then python-mode.el (the one that comes with
Python, not the python.el bundled with recent emacs versions) already
know how to do so.
Yes, I want eval a region, but likely not a python buffer, for example,
in a *w3m* buffer.
>
Else please explain what you're trying to do ?
--
http://mail.python.org/mailman/listinfo/python-list
Oct 21 '08 #2
#! /bin/sh
python -c "import sys;exec(sys.stdin)"
I know this isn't your question, but I think you could write that more
cleanly with:

#!/usr/bin/python
import sys
exec(sys.stdin)
Oct 21 '08 #3
Nathan Seese <un********@lavabit.comwrites:
>#! /bin/sh
python -c "import sys;exec(sys.stdin)"

I know this isn't your question, but I think you could write that more
cleanly with:

#!/usr/bin/python
import sys
exec(sys.stdin)
thanks.
What's the difference between this and mine?

I think what i need actually is a python function like
`file_get_contents' in php:)
--
http://mail.python.org/mailman/listinfo/python-list
Oct 21 '08 #4
On Tue, 21 Oct 2008 11:22:56 +0800, Peter Wang wrote:
Nathan Seese <un********@lavabit.comwrites:
>>#! /bin/sh
python -c "import sys;exec(sys.stdin)"

I know this isn't your question, but I think you could write that more
cleanly with:

#!/usr/bin/python
import sys
exec(sys.stdin)

thanks.
What's the difference between this and mine?
Yours launches an new shell, which then calls python, which then executes
whatever it finds in stdin as Python code.

The second one just launches Python directly.
I think what i need actually is a python function like
`file_get_contents' in php:)

I think that would be:

contents = open(filename).read()


--
Steven
Oct 21 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.