473,385 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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:

Expand|Select|Wrap|Line Numbers
  1. #Filename: break.py
  2.  
  3. while True:
  4.     s = (input('Enter something : '))
  5.     if s == 'quit':
  6.         break
  7.     print('Lenght of the string is', len(s))
  8. 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.
May 10 '10 #1
2 1330
Glenton
391 Expert 256MB
@giggsteve8
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!
May 11 '10 #2
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
May 11 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: James Pittman | last post by:
Hi, I have a PHP script running in a Cron job in Unix, using the "php" command-line command executable. How do I get the path to the script, from within the script? I've tried all the $_SERVER...
6
by: vishal | last post by:
hi how can i get the file name from which the current executing file is called. i m making a scrript which will be called from many other scripts. this script performs some calculation and then...
2
by: Fork | last post by:
Hi, I am trying to execute a script from the command line as follows; c:\program files\mysql\bin>mysql -u root newsman < servers3.mysql But this gives me the following error; ERROR 1064...
1
by: Phil | last post by:
Hi, I have my create statments for tables, procedures, views, etc in individual Transact-SQL script files (.sql). I wnat to write another script file that executes these scripts in the...
3
by: Mike | last post by:
Hi, I am trying to resize a HTML table through Javascript. When the user control loads the first time, the table is resized, but then it doesn't anymore. I am using the following code in the...
2
by: Tumurbaatar S. | last post by:
Hi! I cannot imagine how to create db from a script file and execute other DDL statements on this new db. Currently I use 'psql -f file' to perform all needed DDL statements except of create db....
0
by: RobF | last post by:
I created a script that will make a backup of db2 since I will be using cron to run this I'm using sudo to run the script as db2inst1. Although, this does not work it give me the error: SQL10007N...
1
by: 4umurali | last post by:
Hi All, I want to execute the html in ny text area. but it should not excute any scripts, evethandlers(like onload, onblur, onclick...). Particular page should be safe from xss also excute some...
1
by: lonewolfbw | last post by:
I have the following VBScript which I can execute from my workstation (I am a domain admin), in order to change the local computer's administrator password. However, I am noticing an oddity. ...
4
by: karuppiahdas | last post by:
Hi I am facing a problem in executig the javascript in innerHtml. I got a login screen(jsp page), with two form in the bodyl.One form is wrapped by a div tag.Which has got the login...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.