Re: Converting .py files to batch files.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matias Surdi

    Re: Converting .py files to batch files.

    aditya shukla escribió:
    How can we convert .py files to batch files? is there any library for this?
    >
    >
    Aditya
    >
    >
    ------------------------------------------------------------------------
    >
    --
    http://mail.python.org/mailman/listinfo/python-list
    Maybe py2exe can help you.

  • Michael Palmer

    #2
    Re: Converting .py files to batch files.

    On Sep 15, 3:04 pm, Matias Surdi <matiassu...@gm ail.comwrote:
    aditya shukla escribió:
    >
    How can we convert .py files to batch files? is there any library for this?
    >
    Aditya
    >
    ------------------------------------------------------------------------
    >>
    Maybe py2exe can help you.
    I assume you are on Windows? Let's assume you have a file stuff.py
    that reads:

    import os
    print os.listdir('.') # list current directory, good enough for
    testing...

    Then, insert the following line at the top:

    @setlocal enableextension s & python -x %~f0 %* & goto :EOF

    Now save this file as stuff.cmd somewhere along your PATH. Now calling
    'stuff' should execute your file.
    On Linux, you would instead insert the shebang line that points to
    your python interpreter, such as

    #!/usr/bin/python

    at the top and also set the executable bit, but I suppose if you use
    Linux at all you know that.

    Comment

    • Gabriel Genellina

      #3
      Re: Converting .py files to batch files.

      En Mon, 15 Sep 2008 20:36:05 -0300, Michael Palmer <m_palmer45@yah oo.ca>
      escribió:
      >aditya shukla escribió:
      >>
      How can we convert .py files to batch files? is there any library for
      >this?
      >
      I assume you are on Windows? Let's assume you have a file stuff.py
      that reads:
      >
      import os
      print os.listdir('.') # list current directory, good enough for
      testing...
      >
      Then, insert the following line at the top:
      >
      @setlocal enableextension s & python -x %~f0 %* & goto :EOF
      >
      Now save this file as stuff.cmd somewhere along your PATH. Now calling
      'stuff' should execute your file.
      Cool! I'd enclose the first argument in quotes "%~f0" - in case the path
      contains any whitespace.

      --
      Gabriel Genellina

      Comment

      • r0g

        #4
        Re: Converting .py files to batch files.

        Michael Palmer wrote:
        On Sep 15, 3:04 pm, Matias Surdi <matiassu...@gm ail.comwrote:
        >aditya shukla escribió:
        >>
        >>How can we convert .py files to batch files? is there any library for this?
        >>Aditya
        >>------------------------------------------------------------------------
        <snip>On Linux, you would instead insert the shebang line that points to
        your python interpreter, such as
        >
        #!/usr/bin/python
        >
        at the top and also set the executable bit, but I suppose if you use
        Linux at all you know that.
        Doh! I'm new to Linux and so I didn't know that, thanks!
        One small snag though, it doesn't work on my system :-(
        I did both steps, the shebang and the execute bit but nada...

        r0g@steppa:~/Desktop/py$ ls
        kickstart.py kickstart.py~ kicktest.py kicktest.py~
        r0g@steppa:~/Desktop/py$ kickstart.py
        bash: kickstart.py: command not found

        Any ideas why this might be? A path thing? I'm on Ubuntu 8.04 / Py2.5

        Thanks,

        Roger.

        Comment

        • Grant Edwards

          #5
          Re: Converting .py files to batch files.

          On 2008-09-17, r0g <aioe.org@techn icalbloke.comwr ote:
          r0g@steppa:~/Desktop/py$ ls
          kickstart.py kickstart.py~ kicktest.py kicktest.py~
          r0g@steppa:~/Desktop/py$ kickstart.py
          bash: kickstart.py: command not found
          >
          Any ideas why this might be?
          Yes.
          A path thing?
          Yes.

          Linux systems generally don't have the current directory in the
          PATH that's searched for executbles (it's regarded as a rather
          serious security problem if you do).

          Try doing this:

          ./kickstart.py

          --
          Grant Edwards grante Yow! Look into my eyes and
          at try to forget that you have
          visi.com a Macy's charge card!

          Comment

          • r0g

            #6
            Re: Converting .py files to batch files.

            Grant Edwards wrote:
            On 2008-09-17, r0g <aioe.org@techn icalbloke.comwr ote:
            >
            >r0g@steppa:~/Desktop/py$ ls
            >kickstart.py kickstart.py~ kicktest.py kicktest.py~
            >r0g@steppa:~/Desktop/py$ kickstart.py
            >bash: kickstart.py: command not found
            >>
            >Any ideas why this might be?
            >
            Yes.
            >
            >A path thing?
            >
            Yes.
            >
            Linux systems generally don't have the current directory in the
            PATH that's searched for executbles (it's regarded as a rather
            serious security problem if you do).
            >
            Try doing this:
            >
            ./kickstart.py
            >
            Brilliant! :D Thanks v.much for that, turns out the very same thing had
            been driving me nuts a few days earlier when I was trying to run an
            installer I had downloaded, bit of an Izzard Printer moment LOL -


            Thanks again!

            Roger.



            Comment

            Working...