|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
the 'stats' class
I wanted to use the 'reverse_order( )' object of the Stats class. How do I go abt it?
I did something like----> obj1=Stats() but this is giving me an error tho' I used to do it the same way with the classes defined by me... how do I access the object? Pls guide! Thanks & Rgds, Subha ![]() |
|
#2
|
||||
|
||||
|
Just a guess but unless you used the from module import name from to import Stats() you need to preface Stats() with the modules name.
Could you post your program here; if it is too long then you'll to zip it up and attach it using the "Attach File" section of "Additional options" (under the form you use to post). Also, a copy of the error message being returned by Python would be helpful. Later Subha, Mark. |
|
#3
|
|||
|
|||
|
Hi Mark,
Suppose I've made this class Code:
>>> class myClass: ... def name(self,myName): ... self.name=myName ... return "Hi %s" %(self.name) fine! then I mk an object 'x' of this class Code:
>>> x=myClass() now I call the method 'name' Code:
>>> x.name('Subha')
'Hi Subha'
So this how it goes! Now I tried the same way with Stats Class too but that didn't work there. I wanted to use the 'reverse_order( ) ' method on the same lines ...but that cldn't be done. Code:
object=Stats() Traceback (most recent call last): File "<interactive input>", line 1, in ? NameError: name 'Stats' is not defined This is the error it gave...do I've to import anything before using Stats...n the prob is how do I define an object of class Stats...n then finally using the method reverse_order()... thats my question!! Thanks & Rgds, Subha ![]() |
|
#4
|
||||
|
||||
|
The Profiler is petty complex... well, to a degree. You really need to sit down and read the documentation (below) before you start using it properly.
A much simpler way to do this kind of thing is to use the timeit module: http://www.python.org/doc/2.3.4/lib/module-timeit.html Code:
>>> import profile, pstats
>>>
>>> profile.run('foo()', 'fooProfile')
>>>
>>> aStatsInstance = pstats.Stats('fooProfile')
>>> reversed = aStatsInstance.reverse_order()
>>> reversed.print_stats()
Sat Oct 30 17:37:55 2004 fooProfile
3 function calls in 0.001 CPU seconds
...
As you can see, you have to import the profile and pstats modules before the Stats class will be defined; pretty simple . Anyway, as promised heres a link to the profiler documentation.http://docs.python.org/lib/profile.html Take care, Mark. |
|
#5
|
|||
|
|||
|
Thanks for that!
You made it really simple...but one thought that comes to my mind is that ....whats the use of profiler...I mean it can give the information abt various things...but where can we actually put to use such data. Thanks & Rgds, Subha ![]() |
|
#6
|
||||
|
||||
|
Generally we'd use the profiler to optimize/polish a working Python program; maybe when we want to improve performance – test an algorithm maybe. In theory it could probably help with debugging too, but thats probably overkill
.From the documentation: Quote:
And, thats pretty much it. Simple a' .Mark. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > the 'stats' class |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|