New to Python

Jimmie Webb webbsoft2 at alltel.net
Thu Sep 23 13:46:31 CEST 2004


Thanks to all the great helpful off-post comments that I received from this
group.  Glad to know there are some people out there that can be "friendly"
and "helpful".  It is nice to know some people will help and not call you
lazy or stupid.  Sorry,  I just felt like I walked into the middle of a
pit-bull attack.

-Jimmie Webb





"w" <webbsoft2 at alltel.net> wrote in message
news:a1ff320f.0409211158.29e6256b at posting.google.com...
> 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.0
0000,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.0
0000,2004262,2004282),






More information about the Python-list mailing list