[Bf-python] Little error with 228c

Stephen Swaney sswaney at swbell.net
Mon Sep 29 20:24:53 CEST 2003


Manuel Bastioni wrote:
> 
> > The problem we have here comes from the way we use
> > the our setattrfunc to call methods to set attributes.
> > This is basically an excellent idea because the setXXX
> > methods do range checking and clamping and other nify things.
> 
> This mean the correct style is to use is get and set function
> where is possible, right?

This is a bit of a philosophical question.  In a language
like C++ with access controls, classes tend to have protected
data members and public data access functions.  Python lacks
this and assumes everyone will play nicely.

> If I use set and get, I'm sure about future changes?

It's probably safer in that you are protected against changes
in the internal structure of an object.  Our python objects
are wrappers around the actual blender objects and some elements
do not actually exist in python form.  Some members in our
Object type are protected against direct access.  For example,
ob.track= is not allowed.

On the other hand, obj.name= is a common python idiom and in
bpython it eventually goes through the same code path as 
obj.setName(). Both styles *should* work!
 
> > A patch is attached.
> 
> Thanks!
> However I'm not able to compile the source :-(

I am not surprised.  The patch was the result of a binge of
late night coding madness, errr, I mean inspiration.  I felt
responsible since I had 'fixed' setName() to use the correct
arg parsing call.  I did not realize that this broke ob.name=
or that this was only the symptom of a deeper problem.

At the risk of sounding rude, this is not much of a bug report.
An error message or a line number or something would be helpful.
I would be happy to fix it, but more information is necessary.
As the C++ joke goes:

catch(...)
{
    printf("It worked on my machine\n");
}

( /me now pours gasoline on self and lights match )
You do realize that the patch is not source code that can
be compiled directly, but a patch that must be applied to
Object.c in the .../python/api2_2x directory, yes?

> 
> A little question: I'm a bit confused about get and Get (set and Set).
> This code produce a series of beep and a lot of strange characters:
> 
> foo = Object.getSelected()
> 
> this code work fine:
> 
> foo = Object.GetSelected()

They basically do the same thing, but getSelected() is deprecated.
As was explained to me, the function is a module method ( it
is not bound to an object instance like obj.getName() ).  Under
the New Regime, module methods get capitalized like GetSelected.

The beeping and strange characters are likely from this message in 
getSelected() right before it calls GetSelected:

 PyErr_Warn (PyExc_DeprecationWarning,
            "The Object.getSelected() function will be removed in "\
             "Blender 2.29\n" \
             "Please update the script to use Object.GetSelected");

Think of it as a message from the future!

> Ciao (excuse for bad english),
> 
>      Manuel

No apologies needed, Manuel.  Your English is good, very functional.
My compliments!

> 
> PS::   for models at paposo.com: using 'Base' instead "Base",
> Blender crash !!!

In theory, this should not make any difference.
Python is happy with either single or double quotes.

The fact that this crashes has more to do with the
argument passing being wrong.  But we already knew that,
didn't we?

-- 
Stephen Swaney			
sswaney at swbell.net



More information about the Bf-python mailing list