473,327 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

New to Python

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),
Jul 18 '05 #1
9 2902
w wrote:
excuse my ignorance.**I*cannot*get*this*simple*program*to*ca lculate
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.


x = int(y)
or
x = float(y)
???

Thomas
Jul 18 '05 #2
I tried x = float(nCost) but keep getting an error

ValueError: Invalid literal for float(): EATE TA
"Thomas Krüger" <th************@gmx.net> wrote in message
news:ci*************@news.t-online.com...
w 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.


x = int(y)
or
x = float(y)
???

Thomas


Jul 18 '05 #3
In <YU***************@fe61.usenetserver.com>, Jimmie Webb wrote:
I tried x = float(nCost) but keep getting an error

ValueError: Invalid literal for float(): EATE TA


Maybe the slice values are just wrong? Have you printed all your
variables after picking them from the string to make sure they contain
what you expect?

Ciao,
Marc 'BlackJack' Rintsch
Jul 18 '05 #4
Yes, They look good to me. The nCost Value is 0022.63.
but I still get the error ValueError: Invalid literal for float(): EATE TA.

What does the 'EATE TA' mean?

Thanks!
"Marc 'BlackJack' Rintsch" <bj****@gmx.net> wrote in message
news:pa****************************@gmx.net...
In <YU***************@fe61.usenetserver.com>, Jimmie Webb wrote:
I tried x = float(nCost) but keep getting an error

ValueError: Invalid literal for float(): EATE TA


Maybe the slice values are just wrong? Have you printed all your
variables after picking them from the string to make sure they contain
what you expect?

Ciao,
Marc 'BlackJack' Rintsch


Jul 18 '05 #5
Jimmie Webb <we*******@alltel.net> wrote:
I tried x = float(nCost) but keep getting an error
ValueError: Invalid literal for float(): EATE TA


Come on, do some basic debugging! Insert 'print repr(nCost)' before the
conversation and look at what you really are feeding to the float()
function. Well, we already now it: at some point you feed the string 'EATE
TA' to float(), and it obviously cannot convert this to a number.

Jere
--
Lord, make my words as sweet as honey, for one day I may have to eat them
- Daryl Benson
Jul 18 '05 #6
On 2004-09-21, w <we*******@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),

Jul 18 '05 #7
Jimmie Webb wrote:
Yes, They look good to me. The nCost Value is 0022.63.
but I still get the error ValueError: Invalid literal for float(): EATE TA.

What does the 'EATE TA' mean?

float('EATA TE') Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: invalid literal for float(): EATA TE
float('this not a float!') Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: invalid literal for float(): this not a float!
float ('check your data file and recheck your code')

Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: invalid literal for float(): check your data file and
recheck your code
-Peter
Jul 18 '05 #8
Gee whiz. Don't jump down my throat for some oversite. It's not like I
haven't put forth an effort trying to find out the problem before posting!
Yeah, your right I was reading the "CREATE TABLE line out of the SIL file.
Thanks (I think)
"Jere Kahanpaa" <ka******@sky1.astro.helsinki.fi> wrote in message
news:ci**********@oravannahka.helsinki.fi...
Jimmie Webb <we*******@alltel.net> wrote:
I tried x = float(nCost) but keep getting an error
ValueError: Invalid literal for float(): EATE TA


Come on, do some basic debugging! Insert 'print repr(nCost)' before the
conversation and look at what you really are feeding to the float()
function. Well, we already now it: at some point you feed the string 'EATE
TA' to float(), and it obviously cannot convert this to a number.

Jere
--
Lord, make my words as sweet as honey, for one day I may have to eat them
- Daryl Benson


Jul 18 '05 #9
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" <we*******@alltel.net> wrote in message
news:a1**************************@posting.google.c om...
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),

Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.