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 descriptorAnd 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 -- http://mail.python.org/mailman/listinfo/python-list
