473,387 Members | 1,745 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,387 software developers and data experts.

I need some advice/help on running my scripts

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
1 1174
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: mr.iali | last post by:
Hi Everyone I would like to get into software developent using a programming language like c++, java or pl/sql for oracle. I have no idea where to start from. Which language is there more...
4
by: Spare Brain | last post by:
Hi, I recently installed SuSE 9.3 on x86, and it seems to contain scripts "apache2" and "mysql" in the /etc/init.d folder. However, these two (Apache or MySQL) are not running when I fresh...
4
by: techme | last post by:
I am surprised at how little info there is on this topic. We converted to DB2 v8.1.1.72 painlessly a few months ago. For specific reasons, we stayed on 32-bit. Our OS is AIX 5.2 and our hardward...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
2
by: Dave Hughes | last post by:
Just noticed something rather annoying after upgrading my test box (a Linux server running DB2 UDB v8 for LUW) to fixpak 11 (for reference it was previously on fixpak 7). In the past I've relied...
9
by: laststubborn | last post by:
Dear All, We have a big concern in our Database system. We have 2000 transactions daily in our database. We need to replicate some how the database for our fail over setup. I tried transactional...
4
by: tootsuite | last post by:
Help. I have been tasked with upgrading a 2000 instance to 2005. I have actually done this before, but it was a long time ago, and I didn't do it alone. Now, the sitation is little different, and...
12
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed...
2
by: jon121970 | last post by:
I'm new here.. I am hoping to get some Professional Advice. I want to start my own online Auction. I anticipate it will grow into a high volume/high traffic online auction. I need some...
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...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.