dumb newbie questions

Jonathan Gardner jgardn at alumni.washington.edu
Thu Jan 17 16:46:58 EST 2002


> Hope this was slow enough. You seem to have grasped most of the essentials
> - I guessed you had at least some experience in another programming
> language, so maybe you're doingt better than you think. Your output code
> looks OK. See how it goes with these changes.
>

One little thing I want to add....

When you are writing a serious program, like, let's say a program that 
calculates the inverse of square matrices, you'll want to avoid user input 
like the plague. Why? If you have to keep typing, you get angry because you 
make minor mistakes, and it is also tedious. Plus, when you are entering a 
matrix, you can potentially be entering hundreds of values. When is the last 
time you have never made a mistake entering hundreds of values?

What you may want to do is accept a file for simplicities sake. The file can 
be in the format of:

1.1 1.1 1.1 1.1
1.1 1.1 1.1 1.1
1.1 1.1 1.1 1.1
1.1 1.1 1.1 1.1

It should be easy enough to edit the file to your liking, and use it over and 
over again. And you can keep several files lying around as test cases to see 
if your code is functioning properly.

You can take your shell (your not using Windows, are you?) and dump the file 
into your program as stdin.

$ cat matrix.txt | python inverse.py

Of course, you can code the script (using os.args) to open the file by itself 
and read the contents. Windows people will like this.

$ python inverse.py matrix.txt

Or you can code it to default to the stdin if there are no arguments.

If this is way above your head, then just keep it in the back of your mind 
and continue on with the book and its examples.

Jonathan




More information about the Python-list mailing list