New to Python
Lee Harr
missive at frontiernet.net
Tue Sep 21 16:37:53 EDT 2004
On 2004-09-21, w <webbsoft2 at alltel.net> wrote:
> 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
>
Put your print statement _before_ you do any calculations, so you
can see what you are trying to calculate with ...
>
> 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),
More information about the Python-list
mailing list