W
w
excuse my ignorance. I cannot get this simple program to calculate
the formula.
The error message is unsupported operand type(s) str. I know the data
that I'm reading from the file is a string but I cannot convert it to
a float or int.
The code a sample form the data file are below.
# Calculate Gross Profit from SIL File
import os.path
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),
the formula.
The error message is unsupported operand type(s) str. I know the data
that I'm reading from the file is a string but I cannot convert it to
a float or int.
The code a sample form the data file are below.
# Calculate Gross Profit from SIL File
import os.path
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),