[reportlab-users] BarLabelFormat

Marcus Vinicius Laranjeira reportlab-users@reportlab.com
Fri, 26 Jul 2002 13:12:57 -0300


--=====================_3047284==.ALT
Content-Type: text/plain; charset="iso-8859-1"; format=flowed
Content-Transfer-Encoding: quoted-printable

The problem is:

I have a data series in seconds, and I need to format them in the "HH:MM"=20
forma, for example:

seconds =3D 45966.54
minutes =3D seconds / 60.00
hour =3D 0
while minutes <=3D 60:
     hour =3D hour + 1
     minutes =3D minutes - 60
minutes =3D minutes + 0.50
minutes =3D round(minutes)
fmt =3D ""
if hour < 10:
     fmt =3D fmt + "0"
fmt =3D fmt + str(hour)
fmt =3D fmt + ":"
if minutes < 10:
     fmt =3D fmt + "0"
fmt =3D fmt + str(minutes)
return fmt

but this is a method of a object, so the signature of the object I did this=
=20
way:

     def _formatHour(self, seconds):
         # the code above

and I call this way:

     self.bc.barLabelFormat =3D self._formatHour(self)

and I got this error:

Traceback (most recent call last):
   File "test.py", line 10, in ?
     y =3D x.GenerateGraph()
   File "AvgTTR.py", line 198, in GenerateGraph
     self.bc.barLabelFormat =3D self._formatHour()
   File "AvgTTR.py", line 106, in _formatHour
     minutes =3D seconds / 60.00
TypeError: unsupported operand type(s) for /: 'instance' and 'float'

And if I print the variable seconds, I got:

<AvgTTR.AvgTTR instance at 0x0108B1E0>

How do I solve this problem???

Thanks !


At 14:33 26/07/02 +0200, you wrote:
>Marcus Vinicius Laranjeira:
>>
>>myBarChar.BarLabelFormat =3D ???????????
>
>This general sample case should do (untested):
>
>def format(num):
>     return "-%03d-" % num
>
>...
>myBarChar.BarLabelFormat =3D format
>...
>
>Dinu
>
>_______________________________________________
>reportlab-users mailing list
>reportlab-users@reportlab.com
>http://two.pairlist.net/mailman/listinfo/reportlab-users




Marcus Vinicius Laranjeira
MON Center

Datacraft do Brasil - (http://www.datacraft.com.br)
R. Tenente Negr=E3o, 140 - 8o. Andar
Itaim Bibi - S=E3o Paulo - SP - 04530-030
Tel: +55-11-3053-0241
Fax: +55-11-3053-0220
--=====================_3047284==.ALT
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
The problem is:<br><br>
I have a data series in seconds, and I need to format them in the
&quot;HH:MM&quot; forma, for example:<br><br>
seconds =3D 45966.54<br>
minutes =3D seconds / 60.00<br>
hour =3D 0<br>
while minutes &lt;=3D 60:<br>
&nbsp;&nbsp;&nbsp; hour =3D hour + 1<br>
&nbsp;&nbsp;&nbsp; minutes =3D minutes - 60<br>
minutes =3D minutes + 0.50<br>
minutes =3D round(minutes)<br>
fmt =3D &quot;&quot;<br>
if hour &lt; 10:<br>
&nbsp;&nbsp;&nbsp; fmt =3D fmt + &quot;0&quot;<br>
fmt =3D fmt + str(hour)<br>
fmt =3D fmt + &quot;:&quot;<br>
if minutes &lt; 10:<br>
&nbsp;&nbsp;&nbsp; fmt =3D fmt + &quot;0&quot;<br>
fmt =3D fmt + str(minutes)<br>
return fmt<br><br>
but this is a method of a object, so the signature of the object I did
this way:<br><br>
&nbsp;&nbsp;&nbsp; def _formatHour(self, seconds):<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # the code above<br><br>
and I call this way:<br><br>
&nbsp;&nbsp;&nbsp; self.bc.barLabelFormat =3D
self._formatHour(self)<br><br>
and I got this error:<br><br>
Traceback (most recent call last):<br>
&nbsp; File &quot;test.py&quot;, line 10, in ?<br>
&nbsp;&nbsp;&nbsp; y =3D x.GenerateGraph()<br>
&nbsp; File &quot;AvgTTR.py&quot;, line 198, in GenerateGraph<br>
&nbsp;&nbsp;&nbsp; self.bc.barLabelFormat =3D self._formatHour()<br>
&nbsp; File &quot;AvgTTR.py&quot;, line 106, in _formatHour<br>
&nbsp;&nbsp;&nbsp; minutes =3D seconds / 60.00<br>
TypeError: unsupported operand type(s) for /: 'instance' and
'float'<br><br>
And if I print the variable seconds, I got:<br><br>
&lt;AvgTTR.AvgTTR instance at 0x0108B1E0&gt;<br><br>
How do I solve this problem???<br><br>
Thanks !<br><br>
<br>
At 14:33 26/07/02 +0200, you wrote:<br>
<blockquote type=3Dcite class=3Dcite cite>Marcus Vinicius Laranjeira:<br>
<blockquote type=3Dcite class=3Dcite cite><br>
myBarChar.BarLabelFormat =3D ???????????</blockquote><br>
This general sample case should do (untested):<br><br>
def format(num):<br>
&nbsp;&nbsp;&nbsp; return &quot;-%03d-&quot; % num<br><br>
...<br>
myBarChar.BarLabelFormat =3D format<br>
...<br><br>
Dinu<br><br>
_______________________________________________<br>
reportlab-users mailing list<br>
reportlab-users@reportlab.com<br>
<a href=3D"http://two.pairlist.net/mailman/listinfo/reportlab-users"=
 eudora=3D"autourl">http://two.pairlist.net/mailman/listinfo/reportlab-users=
</a><br>
</blockquote>
<x-sigsep><p></x-sigsep>
<font face=3D"Courier New, Courier"><br><br>
<br>
Marcus Vinicius Laranjeira<br>
MON Center <br><br>
Datacraft do Brasil -
(<a href=3D"http://www.datacraft.com.br/" eudora=3D"autourl">http://www.data=
craft.com.br</a>)
<br>
R. Tenente Negr=E3o, 140 - 8o. Andar <br>
Itaim Bibi - S=E3o Paulo - SP - 04530-030 <br>
Tel: +55-11-3053-0241<br>
Fax: +55-11-3053-0220</font></html>

--=====================_3047284==.ALT--