By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 1,932 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

I need some advice/help on running my scripts

P: n/a
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?

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

[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

[D:\Steve]$ type input.txt | python test.py
0:A
1:B
2:C
3:D
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
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.