How to extract script from a non-python directory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • giggsteve8
    New Member
    • May 2010
    • 4

    How to extract script from a non-python directory

    I'm very, very new, and am working with Python 3.1.2. New as in installed last night, and working through a tutorial.

    I wrote a simple script to aid in learning to break a 'while: True' loop.

    My question is, why can I NOT run this script from a directory other than the \python31 directory? I have the python31 directory set in my path.

    I'm running XP, if that helps. I can run other programs just fine from any other directory. Does this utilize something in the Python directory that the other scripts did not?

    Here is the script:

    Code:
    #Filename: break.py
    
    while True:
        s = (input('Enter something : '))
        if s == 'quit':
            break
        print('Lenght of the string is', len(s))
    print('Done')
    Really appreciate your help! Very excited to continue learning this.

    -Steve

    P.S. Do I need to point to the directory at the top of my file with #!? This was hinted at in the tutorial, but again, I'm not sure.
    P.P.S. The indentations aren't showing up on this forum, but they are correct.
  • Glenton
    Recognized Expert Contributor
    • Nov 2008
    • 391

    #2
    Originally posted by giggsteve8
    Hi guys:

    I'm very, very new, and am working with Python 3.1.2. New as in installed last night, and working through a tutorial.

    I wrote a simple script to aid in learning to break a 'while: True' loop.

    My question is, why can I NOT run this script from a directory other than the \python31 directory? I have the python31 directory set in my path.

    I'm running XP, if that helps. I can run other programs just fine from any other directory. Does this utilize something in the Python directory that the other scripts did not?

    Here is the script:

    #Filename: break.py

    while True:
    s = (input('Enter something : '))
    if s == 'quit':
    break
    print('Lenght of the string is', len(s))
    print('Done')

    Really appreciate your help! Very excited to continue learning this.

    -Steve

    P.S. Do I need to point to the directory at the top of my file with #!? This was hinted at in the tutorial, but again, I'm not sure.
    P.P.S. The indentations aren't showing up on this forum, but they are correct.
    Hi, and welcome to python! Enjoy the ride. Please use code tags when posting - that will help with the indentation.

    The #! thing is to make the file runnable from a linux machine. Generally good practice to have it in place, but makes no difference to you. (In fact I use Ubuntu, and often forget to put it in, since I normally run my scripts from a GUI and so it makes no difference).

    I'm guessing that you've saved the break.py file in your python31 directory? IMHO, you'd be better off putting it somewhere sensible like your My Documents.

    What happens is that the command "python" is available anywhere, because it's in the path. So if you go to the directory where break.py is, you can run python break.py. However, the path is only for executables (.com, .exe, .bat and whatnot) as far as I know. So break.py would not be detected anywhere other than where it is.

    What are you using to edit the code? For the level of scripting that python is commonly used for, you'll find IDLE handy. And you can run the code by pressing F5, rather than from the command line. But of course, there's nothing wrong with running from the command line, and it has several advantages.

    Hope this helps.

    Good luck!

    Comment

    • giggsteve8
      New Member
      • May 2010
      • 4

      #3
      Much thanks!

      The resolution to this problem involves me being somewhat of an idiot.

      I certainly understand that the PATH variable should have NO effect whatsoever on running anything but an executable... I just didn't realize "break" is actually an old DOS command that is still around in the XP cmd window for fun.

      You can type break."whatever extension you want" and it will execute, do nothing, and bring up a new prompt. So, just bad luck naming the file "break.py", I suppose. Had me thinking it was actually running. Not sure what's wrong with me today.

      Thank you for your response regardless, you definitely helped me figure it out.

      I'll use the code tags next time, too!

      -Steve

      Comment

      Working...