Windows and python execution

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

    #16
    Re: Windows and python execution

    Peter Hansen wrote:[color=blue]
    > BartlebyScriven er wrote:[color=green][color=darkred]
    >>>>What you need to do is include the following line in autoexec.bat:
    >>>>set .py=c:\python24 \python.exe[/color]
    >>
    >>Whatever works for you. I don't have that command in my autoexec.bat
    >>file and my python scripts execute from any location because the
    >>directory they are stored in is in my PATH variable.[/color][/color]
    ....[color=blue]
    > Merely adding the folder containing the EXE to PATH does *not* let you
    > avoid typing "python" before the script name, as your posts imply.[/color]

    D'oh... okay, people (including me) are reading others' posts with
    preconceptions about what they are talking about in mind.

    The PATHEXT thing is required to be able to type just "scriptname "
    _without_ the .py extension. Alternatively, it appears there's yet
    another obscurely documented feature involving setting environment
    variables that resemble file extensions, as posted by others. (Where do
    these things come from? It's like Microsoft releases the OS, then
    periodically sends private emails to random people, pointing out obscure
    new features, so that they can tell others in some feeble effort to make
    using Windows look like a grassroots effort or something. How are
    regular mortals supposed to find out about things like "set .py="?)

    The ability to run the script with just "scriptname .py" comes from, I
    believe, having a file association set up with "ftype" and "assoc" or
    the equivalent registry entries. For this to work from _any_ location
    one must have the folder containing the *script* in the PATH, as with
    any executable, while the path specified by FTYPE points to the Python
    executable. (This ftype/assoc file association is set up by the
    standard installer, which is why it works for BartlebyScriven er).

    -Peter

    Comment

    • Daniel Dittmar

      #17
      Re: Windows and python execution

      Tim Roberts wrote:[color=blue]
      > Mark Carter <me@privacy.net > wrote:[color=green]
      >>What you need to do is include the following line in autoexec.bat:
      >>set .py=c:\python24 \python.exe
      >>
      >>This will achieve the desired result. I'm suprised more people don't use it.[/color]
      >
      >
      > They don't use it, because it doesn't do anything. I'd be interested to
      > know where you read that.[/color]

      This is a feature of 4NT, a commercial replacement for cmd.exe. And
      unlike cmd.exe, it even allows redirection of stdin/stdout when a script
      is executed through the extension (the OP's next post is probably going
      to be 'why doesn't redirection work?').

      Daniel

      Comment

      • BartlebyScrivener

        #18
        Re: Windows and python execution

        Some of the confusion probably comes from which installation people
        use. I used the latest ActiveState distribution of Python. As one of
        the other posters observed it automatically adds the .py extension in
        the PATHEXT system variable. At least I didn't put it there. Then, as
        we've discussed, as long as the directory containing your scripts is in
        the path, you can type nothing by "myscript.p y" at the command line and
        your script will execute from any location on the machine.

        rpd

        Peter Hansen wrote:[color=blue]
        > Peter Hansen wrote:[color=green]
        > > BartlebyScriven er wrote:[color=darkred]
        > >>>>What you need to do is include the following line in autoexec.bat:
        > >>>>set .py=c:\python24 \python.exe
        > >>
        > >>Whatever works for you. I don't have that command in my autoexec.bat
        > >>file and my python scripts execute from any location because the
        > >>directory they are stored in is in my PATH variable.[/color][/color]
        > ...[color=green]
        > > Merely adding the folder containing the EXE to PATH does *not* let you
        > > avoid typing "python" before the script name, as your posts imply.[/color]
        >
        > D'oh... okay, people (including me) are reading others' posts with
        > preconceptions about what they are talking about in mind.
        >
        > The PATHEXT thing is required to be able to type just "scriptname "
        > _without_ the .py extension. Alternatively, it appears there's yet
        > another obscurely documented feature involving setting environment
        > variables that resemble file extensions, as posted by others. (Where do
        > these things come from? It's like Microsoft releases the OS, then
        > periodically sends private emails to random people, pointing out obscure
        > new features, so that they can tell others in some feeble effort to make
        > using Windows look like a grassroots effort or something. How are
        > regular mortals supposed to find out about things like "set .py="?)
        >
        > The ability to run the script with just "scriptname .py" comes from, I
        > believe, having a file association set up with "ftype" and "assoc" or
        > the equivalent registry entries. For this to work from _any_ location
        > one must have the folder containing the *script* in the PATH, as with
        > any executable, while the path specified by FTYPE points to the Python
        > executable. (This ftype/assoc file association is set up by the
        > standard installer, which is why it works for BartlebyScriven er).
        >
        > -Peter[/color]

        Comment

        • Roger Upole

          #19
          Re: Windows and python execution

          The PATHEXT allows you to execute the script
          without typing the .py extension.

          Roger

          "BartlebyScrive ner" <rpdooling@gmai l.com> wrote in message news:1135824774 .254022.37550@g 14g2000cwa.goog legroups.com...[color=blue]
          > Some of the confusion probably comes from which installation people
          > use. I used the latest ActiveState distribution of Python. As one of
          > the other posters observed it automatically adds the .py extension in
          > the PATHEXT system variable. At least I didn't put it there. Then, as
          > we've discussed, as long as the directory containing your scripts is in
          > the path, you can type nothing by "myscript.p y" at the command line and
          > your script will execute from any location on the machine.
          >
          > rpd
          >
          > Peter Hansen wrote:[color=green]
          >> Peter Hansen wrote:[color=darkred]
          >> > BartlebyScriven er wrote:
          >> >>>>What you need to do is include the following line in autoexec.bat:
          >> >>>>set .py=c:\python24 \python.exe
          >> >>
          >> >>Whatever works for you. I don't have that command in my autoexec.bat
          >> >>file and my python scripts execute from any location because the
          >> >>directory they are stored in is in my PATH variable.[/color]
          >> ...[color=darkred]
          >> > Merely adding the folder containing the EXE to PATH does *not* let you
          >> > avoid typing "python" before the script name, as your posts imply.[/color]
          >>
          >> D'oh... okay, people (including me) are reading others' posts with
          >> preconceptions about what they are talking about in mind.
          >>
          >> The PATHEXT thing is required to be able to type just "scriptname "
          >> _without_ the .py extension. Alternatively, it appears there's yet
          >> another obscurely documented feature involving setting environment
          >> variables that resemble file extensions, as posted by others. (Where do
          >> these things come from? It's like Microsoft releases the OS, then
          >> periodically sends private emails to random people, pointing out obscure
          >> new features, so that they can tell others in some feeble effort to make
          >> using Windows look like a grassroots effort or something. How are
          >> regular mortals supposed to find out about things like "set .py="?)
          >>
          >> The ability to run the script with just "scriptname .py" comes from, I
          >> believe, having a file association set up with "ftype" and "assoc" or
          >> the equivalent registry entries. For this to work from _any_ location
          >> one must have the folder containing the *script* in the PATH, as with
          >> any executable, while the path specified by FTYPE points to the Python
          >> executable. (This ftype/assoc file association is set up by the
          >> standard installer, which is why it works for BartlebyScriven er).
          >>
          >> -Peter[/color]
          >[/color]




          ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
          http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
          ---= East/West-Coast Server Farms - Total Privacy via Encryption =---

          Comment

          • Thorsten Kampe

            #20
            Re: Windows and python execution

            * Mark Carter (2005-12-26 23:06 +0100)[color=blue]
            > I had installed python 2.4 in the standard way, so py files were already
            > associated with python when you double-clicked them from Explorer. Using
            > my set meant that if I wanted to use py files from the command line, I
            > could just type out the script name (you have to be in the right
            > directory, of course), and it works. Here's a snippit from my
            > autoexec.bat files:
            > set PATH=C:\python2 4;%PATH%
            > set .py=c:\python24 \python.exe[/color]

            If you installed Python the normal way, .py files are already
            associated with Python. Windows uses the registry and doesn't make any
            difference whether you doubleclick a file or type the name on the
            command line

            Comment

            • Peter Hansen

              #21
              Re: Windows and python execution

              Thorsten Kampe wrote:[color=blue]
              > If you installed Python the normal way, .py files are already
              > associated with Python. Windows uses the registry and doesn't make any
              > difference whether you doubleclick a file or type the name on the
              > command line[/color]

              The difference is whether you can execute the script by typing
              "scriptname .py" or merely "scriptname ". With the "set .py" approach
              Mark was mentioning, even though it's not supported by vanilla Windows,
              you can do the latter. Same with setting the PATHEXT environment
              variable, which the ActivePython distribution apparently does. The
              "normal way" of installing Python does *not* set enable this, requiring
              you to execute scripts with the full "scriptname.py" .

              -Peter

              Comment

              Working...