[Tutor] Need help!! I am a new python user
Zakir Hussain
zakir@nortelnetworks.com
Fri, 20 Oct 2000 16:30:35 -0400
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C03AD4.99CF6EC0
Content-Type: text/plain;
charset="iso-8859-1"
I am trying to subtract two values but instead of subtracting it give me an
error
Traceback (innermost last):
File "<pyshell#1>", line 1, in ?
test()
File "d:\Python\metrics.py", line 151, in test
z.process_metrics_file()
File "d:\Python\metrics.py", line 136, in process_metrics_file
self.calc_time()
File "d:\Python\metrics.py", line 115, in calc_time
tot_min = (`end_min`) - (`start_min`)
TypeError: bad operand type(s) for -
can you please help me with that ?
Here is the Example code fragment
start_min = self.sessions[self.current_entry[5]]['start'][0][4]
end_min = self.sessions[self.current_entry[5]]['end'][0][4]
#start_min's value is 40
#end_min's value is 50
so now I am trying to subtract start min
if (end_min > start_min):
total_min = end_min - start_min
print start_min
print end_min
Also if I try to add the velues it concatinates them
e.g: end_min + start_min = 5040
------_=_NextPart_001_01C03AD4.99CF6EC0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2652.35">
<TITLE>Need help!! I am a new python user</TITLE>
</HEAD>
<BODY>
<BR>
<P><FONT SIZE=3D2 FACE=3D"Arial">I am trying to subtract two values =
but instead of subtracting it give me an error </FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Arial">Traceback (innermost last):</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial"> File =
"<pyshell#1>", line 1, in ?</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial"> test()</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial"> File =
"d:\Python\metrics.py", line 151, in test</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial"> =
z.process_metrics_file()</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial"> File =
"d:\Python\metrics.py", line 136, in =
process_metrics_file</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial"> =
self.calc_time()</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial"> File =
"d:\Python\metrics.py", line 115, in calc_time</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial"> tot_min =3D =
(`end_min`) - (`start_min`)</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">TypeError: bad operand type(s) for =
-</FONT>
</P>
<BR>
<BR>
<P><FONT SIZE=3D2 FACE=3D"Arial">can you please help me with that =
?</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Arial">Here is the Example code =
fragment</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Arial">start_min =3D =
self.sessions[self.current_entry[5]]['start'][0][4]</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">end_min =3D =
self.sessions[self.current_entry[5]]['end'][0][4]</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Arial">#start_min's value is 40</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">#end_min's value is 50 </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">so now I am trying to subtract start =
min </FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Arial">if (end_min > start_min):</FONT>
<BR><FONT SIZE=3D2 =
FACE=3D"Arial"> &nb=
sp; total_min =3D end_min - =
start_min </FONT>
<BR> =20
<BR> <FONT SIZE=3D2 =
FACE=3D"Arial">print start_min</FONT>
<BR><FONT SIZE=3D2 =
FACE=3D"Arial"> =
print end_min</FONT>
</P>
<P><FONT SIZE=3D2 FACE=3D"Arial">Also if I try to add the velues it =
concatinates them </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">e.g: end_min + start_min =3D =
5040</FONT>
</P>
<BR>
</BODY>
</HTML>
------_=_NextPart_001_01C03AD4.99CF6EC0--