Can i use this script as a python evaluator?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Wang

    Can i use this script as a python evaluator?


    <code>
    #! /bin/sh
    python -c "import sys;exec(sys.st din)"
    </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.


  • Peter Wang

    #2
    Re: Can i use this script as a python evaluator?

    Bruno Desthuilliers <bdesth.quelque chose@free.quel quepart.frwrite s:
    Peter Wang a écrit :
    ><code>
    >#! /bin/sh
    >python -c "import sys;exec(sys.st din)"
    ></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

    Comment

    • Nathan Seese

      #3
      Re: Can i use this script as a python evaluator?

      #! /bin/sh
      python -c "import sys;exec(sys.st din)"
      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)

      Comment

      • Peter Wang

        #4
        Re: Can i use this script as a python evaluator?

        Nathan Seese <uninverted@lav abit.comwrites:
        >#! /bin/sh
        >python -c "import sys;exec(sys.st din)"
        >
        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_conte nts' in php:)

        Comment

        • Steven D'Aprano

          #5
          Re: Can i use this script as a python evaluator?

          On Tue, 21 Oct 2008 11:22:56 +0800, Peter Wang wrote:
          Nathan Seese <uninverted@lav abit.comwrites:
          >
          >>#! /bin/sh
          >>python -c "import sys;exec(sys.st din)"
          >>
          >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_conte nts' in php:)

          I think that would be:

          contents = open(filename). read()




          --
          Steven

          Comment

          Working...