wang1986one / pyo

Automatically exported from code.google.com/p/pyo
GNU General Public License v3.0
0 stars 0 forks source link

Use repr in pyo classes to print prettier output and information about objects #6

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be nice if objects could print out information about current
properties state instead of printing the name and address of the object.
This can easily be done by defining an __repr__ method in the class and
returning a string : 

def __repr__(self):

        return 'Fade in = {0} seconds, Fade out = {1}
seconds'.format(self._fadein, self._fadeout)

Tested on the Fader object and it works great.

Original issue reported on code.google.com by leca...@gmail.com on 25 Feb 2010 at 9:14

GoogleCodeExporter commented 9 years ago
Note : this is not what the object returns it's just the visual representation 
of the
returned output.

Original comment by leca...@gmail.com on 25 Feb 2010 at 9:22

GoogleCodeExporter commented 9 years ago
Here's an example of what the output looks like :

>>> s.start()
<pyolib.server.Server object at 0x93050>
>>> a = Adsr(attack=.01, decay=.2, sustain=.5, release=.1, dur=5, mul=.5)
>>> a
<pyolib.controls.Adsr object at 0x93910>
>>> f = Fader(fadein=1, fadeout=2, dur=5, mul=.5)
>>> f
Fade in = 1 seconds
Fade out = 2 seconds

Original comment by leca...@gmail.com on 25 Feb 2010 at 9:33

GoogleCodeExporter commented 9 years ago
yep! done!

Original comment by belan...@gmail.com on 26 Feb 2010 at 3:39