New to Python

Batista, Facundo FBatista at uniFON.com.ar
Tue Sep 21 16:27:25 EDT 2004


[webbsoft2 at alltel.net]

#- in_file = open( "s3cga1.new", "r")
#- 
#- while 1:
#-      data = in_file.readline()
#-      if not data:
#- 	    break
#- 
#-      if data[0:1] == "(":
#- 
#- 	nCost = data[ 99:106]
#- 	nPack = data[ 44:48]
#- 
#- 	nRetail = data[ 79:87]
#- 	nQuan = data[ 87:90]
#- 	nAllowance = data[ 147:154]
#- 
#- 	nGp = ( ( nRetail / nQuan ) - ( ( nCost - nAllowance) / 
#- nPack ) ) / (
#- nRetail / nQuan )
#- 
#- 	print nCost, nPack, nQuan, nRetail, nAllowance
#- 
#- 
#- EXAMPLE OF DATA FILE
#- (00007756725434,'*BREYER STRWBRY ICE ',0007,0006,' 56 OZ   
#- ','000216  
#-       
#- ',0004.95,001,2004260,0024.43000,0000000,00000.00,000,0000000
#- ,0000000,0004.00000,2004262,2004282),
#- (00007756725433,'*BREYER PEACH ICE CR',0007,0006,' 56 OZ   
#- ','000224  
#-       
#- ',0004.95,001,2004260,0024.43000,0000000,00000.00,000,0000000
#- ,0000000,0004.00000,2004262,2004282),

You should really consider using ``split()`` to separate the lines in the
files, you won't get bad slices that way.

And use int(), float() or Decimal() to pass a string to number.

Regards.

Facundo Batista
Desarrollo de Red
fbatista at unifon.com.ar
(54 11) 5130-4643
Cel: 15 5097 5024





More information about the Python-list mailing list