Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > I need some advice/help on running my scripts

Reply
Thread Tools

I need some advice/help on running my scripts

 
 
Sean
Guest
Posts: n/a
 
      01-01-2005
For the last couple of months I have been reading and working throught
the examples in Magnus Lie Hetland's Book "Practical Python" This for
all practical purposes is the first computer programming language I
have spent any time at learning, so much of what I have covered in the
book was for the first time.

My problem is that many of the example scripts are run on Linux
machines and I am using Win XP Pro. Here is a specific example of what
is confusing me. If I want to open a file from the dos prompt in some
script do I just write the name of the file I want to open (assuming it
is in the same directory) after the script name?
such as

c:\some_script.py some_text_file.txt

Does piping work the same way in dos as it does on a linux machine?
And last but not least, is there a way to do this all from IDLE?

 
Reply With Quote
 
 
 
 
Steven Bethard
Guest
Posts: n/a
 
      01-01-2005
Sean wrote:
> My problem is that many of the example scripts are run on Linux
> machines and I am using Win XP Pro. Here is a specific example of what
> is confusing me. If I want to open a file from the dos prompt in some
> script do I just write the name of the file I want to open (assuming it
> is in the same directory) after the script name?
> such as
>
> c:\some_script.py some_text_file.txt


It's unclear to me what you want to do here. If your some_script.py
looks like:

import sys
f = file(sys.argv[1])

then yes, you can call some_script.py as above, and the file will be
readable from the 'f' file object.


> Does piping work the same way in dos as it does on a linux machine?


Mostly:

[D:\Steve]$ type test.py
import sys
for i, line in enumerate(sys.stdin):
sys.stdout.write("%i:%s" % (i, line))

[D:\Steve]$ type input.txt
A
B
C
D

[D:\Steve]$ python test.py < input.txt
0:A
1:B
2:C
3

[D:\Steve]$ python test.py > output.txt
Z
Y
X
^Z
^Z

[D:\Steve]$ type output.txt
0:Z
1:Y
2:X

[D:\Steve]$ python test.py < input.txt > output.txt

[D:\Steve]$ type output.txt
0:A
1:B
2:C
3

[D:\Steve]$ type input.txt | python test.py
0:A
1:B
2:C
3


Note however, that you may run into problems if you don't explicitly
call python:

[D:\Steve]$ test.py < input.txt
Traceback (most recent call last):
File "D:\Steve\test.py", line 2, in ?
for i, line in enumerate(sys.stdin):
IOError: [Errno 9] Bad file descriptor

> And last but not least, is there a way to do this all from IDLE?


What exactly do you want to do? You can certainly type something like:

f = file('input.txt')

in IDLE to get access to the 'input.txt' file...

Steve
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Python Scripts with IIS - ASP or Python-based CGI scripts withIIS - which makes more sense? davidj411 Python 0 06-27-2008 04:38 PM
What is required for perl scripts to run correct when launched from rc scripts on HPUX 11? deanjones7@gmail.com Perl Misc 13 09-10-2007 11:58 AM
Stupid question: Making scripts python-scripts Jan Danielsson Python 8 07-22-2005 12:20 AM
Re: Stupid question: Making scripts python-scripts Jp Calderone Python 0 07-21-2005 02:38 PM
Running scripts at server or side client Tarllem ASP .Net 4 03-06-2005 10:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57