[Tutor] Newbie - Not reading file

Barbara Mark bl_mark@hotmail.com
Thu, 25 Oct 2001 11:39:08 -0500


Hello,
I am a programming newbie and Python newbie.  I need some very basic help 
with my first program.  I've looked through some of the archives, and 
someone has borrowed my copy of "Learning Python."
The program does not seem to be reading in the file very well, although the 
imported function calculation works fine.  It will do a correct calculation 
if I offer it a number, but it will not grab the numbers from the opened 
file.  I've tried many things, so what I have below is just a sample.  
Please help, tell me what I'm doing wrong.

The program is:   TaxProgram
The function is:  Tax8.py
The file is:      Incomes.dat

*******I have tried many, but a version of the program reads:
import sys
import Tax8

t = Tax8.tax

x = open('incomes.dat', 'r+')

while x > 0:
	t(x)

*******Again, I have tried many, but a version of the function reads:
def tax(x):      #calculates tax for input income

	print x
	r = []

	if 0 < x < 20000:
		r = x*0.1

	elif 20000 < x < 60000:
		r = (20000 * 0.1) + ((x-20000) * 0.15)

	elif 60000 < x < 200000:
		r = (20000 * 0.1) + (40000 * 0.15) + ((x-60000) * 0.25)

	else:
		r = (20000 * 0.1) + (40000 * 0.15) + (200000 * 0.25) + ((x-200000) * 0.3)

	print r

	return r

******A sample incomes.dat file may read:
10000
15000
50000
0

** Any help would be appreciated.

Thanks.  Blm


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp