Martin Chilvers | 21 Oct 2006 12:54

Thought of the day...

G'day,

So here is my thought for the day:-

"Maximum of ONE loop ('for', 'while') per method."

The reasoning is that methods that handle iteration should (*most of the time*) 
be written such that they:-

1) Either process an entire list of things

or

2) Process a single thing

e.g.

class Foo(HasTraits):

     def some_method(self, ...):
         """ Do some stuff. """

         ...
         ...

         for blargle in self.blargles:
             # You often see a block comment here...
             # ... explaining what is being done to the
             # blargle. If only this comment was in the
             # API docs ;^)
(Continue reading)

Martin Chilvers | 21 Oct 2006 13:02

Re: Interfaces with Traits?

Robert Kern wrote:

> Well, let's just take a look at zope.interface:
> 
> http://svn.zope.org/*checkout*/Zope3/trunk/src/zope/interface/README.txt
> 
> """
> Normally, declarations are inherited::
> 
>    >>> class SpecialFoo(Foo):
>    ...     zope.interface.implements(ISpecial)
>    ...     reason = 'I just am'
>    ...     def brag(self):
>    ...         return "I'm special because %s" % self.reason
> 
>    >>> list(zope.interface.implementedBy(SpecialFoo))
>    [<InterfaceClass __main__.ISpecial>, <InterfaceClass __main__.IFoo>]
> 
>    >>> list(zope.interface.providedBy(SpecialFoo()))
>    [<InterfaceClass __main__.ISpecial>, <InterfaceClass __main__.IFoo>]
> 
> Sometimes, you don't want to inherit declarations.  In that case, you
> can use `implementsOnly`, instead of `implements`::
> 
>    >>> class Special(Foo):
>    ...     zope.interface.implementsOnly(ISpecial)
>    ...     reason = 'I just am'
>    ...     def brag(self):
>    ...         return "I'm special because %s" % self.reason
> 
(Continue reading)

Martin Chilvers | 21 Oct 2006 14:16

Simple meta-class example...

G'day,

Here's a simple meta-class example that just logs messages at each point in the 
class lifecycle... If you haven't used meta-classes before it might be 
interesting... (or not!)...

Martin
""" A simple example that shows the workings of meta-classes. """

# Enthought library imports.
from enthought.logger.api import logger

logger.debug('---------- meta class example ----------')

class ExampleMetaClass(type):
    """ A simple example that shows the workings of meta-classes. """

    def __new__(cls, name, bases, dict):
        """ Creates a class. """

        logger.debug('ExampleMetaClass.__new__: %s, %s, %s', cls, name, bases)

        return super(ExampleMetaClass, cls).__new__(cls, name, bases, dict)

    def __init__(cls, name, bases, dict):
        """ Initializes a class. """

        logger.debug('ExampleMetaClass.__init__: %s, %s', name, bases)
(Continue reading)

Martin Chilvers | 21 Oct 2006 14:22

Bug in example...

Oops... there was a little bug in 'HasTraitsPlus'.... here's the fixed version...
""" Example of how to implement something like 'implements'! """

# Standard library imports.
import sys

# Enthought library imports.
from enthought.traits.has_traits import HasTraits, MetaHasTraits

class MetaHasTraitsPlus(MetaHasTraits):
    """ Example meta-class to show how we can get 'implements' information. """

    def __new__(cls, name, bases, dict):
        """ Creates a class. """

        # Create the class as normal.
        klass = super(MetaHasTraitsPlus, cls).__new__(cls, name, bases, dict)

        # Attach any interface implementation information to the class.
        frame = sys._getframe(1)
        klass.__implements__ = frame.f_locals.get('__implements__', [])

        # As recommended in the Python documentation make sure that we get rid
        # of our frame reference immediately (see the 'inspect' module for
        # details).
        del frame

        return klass
(Continue reading)

Martin Chilvers | 22 Oct 2006 01:39

Re: Thought of the day...

G'day,

>> So here is my thought for the day:-
>> "Maximum of ONE loop ('for', 'while') per method."
>> The reasoning is that methods that handle iteration should (*most of 
>>  the time*) be written such that they:-
>> 1) Either process an entire list of things
>> or
>> 2) Process a single thing
> 
> What is a method that "handles iteration"?  Some methods have to use 
> iteration over two different lists in order to achieve their goal.  I 
> agree with the spirit of this, i.e. factor out pieces of functionality 
> into atomic concepts that can be reused or applied via iteration, but I 
> think it's quite draconian to stipulate that no method should have more 
> than 1 iteration loop, especially in the context of scientific apps 
> where it is common to iterate over very large multi-dimensional or 
> correlated structures.

Thats why I said, *most of the time*. Scientific 'algorithms' are obviously one 
place where the 'rule' can be broken. But, just for fun lets add up the lines 
of that kind of code vs the lines of OO support/framework code in our repositories.

>>              # You often see a block comment here...
>>              # ... explaining what is being done to the
>>              # blargle. If only this comment was in the
>>              # API docs ;^)
> 
> Document *why*, not *how*.  The implementation details of how blargles 
> get transformed into baz-biffles should explicitly *not* be in the API 
(Continue reading)

Peter Wang | 23 Oct 2006 19:16

Re: dynamically fixing a Range using another attribute's value ?

Ash wrote:
>  >>Are you trying to make 'src_j1' be constrained to be between 0 and 
> cell_d1.value?
> 
> yes.. can it be done ?
> 
> -A

Yes, it can be done, but not quite the way you have it written.  You will need 
to write a validator to do it.  I've attached an example.

-Peter


from enthought.traits import HasTraits, Range, Trait, TraitError

def j1_validator(obj, name, value):
    try:
        if 0.0 < value <= obj.cell_d1:
            return value
        else:
            raise TraitError
    except:
        raise TraitError
j1_validator.info = "a value between 0.0 and cell_d1"

class MyProj(HasTraits):

(Continue reading)

Dave Peterson | 23 Oct 2006 16:51

Re: desperate for fortran wrapper

Hi Randy,

Unfortunately, I'm not the best resource to answer your f2py / Fortran 
questions.  I've taken the liberty of forwarding your question to the 
enthought-dev mailing list where you'll have a better chance of getting 
help.

If you're using Python Enthought Edition, or the Enthought Tool Suite 
open source, I'd highly suggest subscribing to the enthought-dev mailing 
list so you can post questions and comments.  You can do so here:
	https://mail.enthought.com/mailman/listinfo/enthought-dev

-- Dave Peterson

Randy Direen wrote:
>     Hi,  I have recently found a great interest in Python and its 
> ability to do complex visualizations via VTK and MayaVi2.  I really want 
> to use it for visualizing the data we are taking here at the National 
> Institute of Standards and Technology in our near field chambers.  A lot 
> of our code is in Fortran90/95 and I would like to use it from Python.  
> I have found f2py but windows XP seems to make using this utility 
> painful.  I know the enthought 2.3 version has f2py and supposedly makes 
> things a little easier but I haven  found it in the 2.4 version.  I was 
> wondering if you could help me out by letting me know what the best way 
> to get my Fortran code to Python.  Thanks
> 
> Randy Direen
> 
> NIST D.O.C.
> 
(Continue reading)

Bryce Hendrix | 23 Oct 2006 20:58

Re: desperate for fortran wrapper

Randy,

F2PY was moved into numpy a while back, some info can be found here:

http://scipy.org/Cookbook/F2Py?highlight=%28f2py%29

Bryce

Dave Peterson wrote:
Hi Randy, Unfortunately, I'm not the best resource to answer your f2py / Fortran questions. I've taken the liberty of forwarding your question to the enthought-dev mailing list where you'll have a better chance of getting help. If you're using Python Enthought Edition, or the Enthought Tool Suite open source, I'd highly suggest subscribing to the enthought-dev mailing list so you can post questions and comments. You can do so here: https://mail.enthought.com/mailman/listinfo/enthought-dev -- Dave Peterson Randy Direen wrote:
Hi, I have recently found a great interest in Python and its ability to do complex visualizations via VTK and MayaVi2. I really want to use it for visualizing the data we are taking here at the National Institute of Standards and Technology in our near field chambers. A lot of our code is in Fortran90/95 and I would like to use it from Python. I have found f2py but windows XP seems to make using this utility painful. I know the enthought 2.3 version has f2py and supposedly makes things a little easier but I haven found it in the 2.4 version. I was wondering if you could help me out by letting me know what the best way to get my Fortran code to Python. Thanks Randy Direen NIST D.O.C.
_______________________________________________ Enthought-dev mailing list Enthought-dev-oRDGkvazHdacsI7C1d+pp9BPR1lH4CV8@public.gmane.org https://mail.enthought.com/mailman/listinfo/enthought-dev

_______________________________________________
Enthought-dev mailing list
Enthought-dev@...
https://mail.enthought.com/mailman/listinfo/enthought-dev
Jeff Strunk | 24 Oct 2006 17:50

GMANE interface

Good morning,

We now have a GMANE interface to the enthought-dev mailing list. I have 
submitted a request that the archives be imported.

http://dir.gmane.org/gmane.comp.python.enthought.devel

Thank you,
Jeff
IT Administrator
Enthought, Inc.
rharder | 24 Oct 2006 18:45

Envisage basics


Hi,
I've been dying to start using Envisage and Mayavi2, but so far I've  
had the impression that I need a PhD in computers science instead of  
physics from the documentation.
Are there any examples of simple Envisage apps that load 3D data,  
provide a set of buttons to do simple manipulations on it, then feed  
the results into Mayavi for visualization?  A great example would be  
something like an FFT app that performs a Fourier Transform at the  
touch of a button.

Previously I've done things like this in Mayavi 1.5 by creating a new  
source module with the tools accessed through the source configuration  
gui.  It's really not the way to go and since Mayavi2 is the wave of  
the future I'd like to start developing for it.

Thanks,
Ross

"A good traveler has no fixed plans, and is not intent on arriving."
                                                               Lao Tzu

Gmane