#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Bombay, India
    Posts
    159
    Rep Power
    13

    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. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Bombay, India
    Posts
    159
    Rep Power
    13
    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
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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.
    programming language development: www.netytan.com Hula

  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Location
    Bombay, India
    Posts
    159
    Rep Power
    13
    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
  10. #6
  11. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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:

    A profiler is a program that describes the run time performance of a program, providing a variety of statistics. This documentation describes the profiler functionality provided in the modules profile and pstats. This profiler provides deterministic profiling of any Python programs. It also provides a series of report generation tools to allow users to rapidly examine the results of a profile operation.
    And, thats pretty much it. Simple a' .

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo