On Fri, 9 May 2008, Martin Schwarzbauer wrote:
> Hi !
>
> In the docu you can find, that 'self' should be the first argument in
> classes.
>
> See:
http://rgruet.free.fr/PQR25/PQR2.5.html#ClassDef>
> or see docu on www.python.org
>
>
>
> William S Fulton schrieb:
>> Haoyu Bai wrote:
>>> Martin Schwarzbauer wrote:
>>>> Hi there!
>>>>
>>>> I use SWIG to use my C++ Code in Python! It work's but in Eclipse I
>>> get
>>>> the warning/error that the first argument should be 'self' -> why
>>>> doesn't SWIG create valid python codE?
>>>>
>>>
>>> Yes, the generated code isn't IDE friendly. But the generated code is
>>> surely *valid* since it can runs. I think Eclipse gives you some warning
>>> but no error, right? So you can simply ignore it.
>>>
>> Is SWIG generating code that is possibly deprecated? Maybe the self
>> should be generated and if that will work too we should fix this. I'd
>> need to defer to a Python expert though.
>>
>> William
As that page says, this is a convention. It is not incorrect to do
otherwise.
You may ask "why doesn't SWIG follow this convention?" I think we're
talking about methods that are declared like this:
def Foo(*args):
SWIG uses the '*' mechanism to receive all arguments as a tuple. It
wouldn't make sense to change "args" to "self", because it's not the class
instance, it's a tuple with the class instance as its first element.
Things could be declared like this instead:
def Foo(self, *args):
but that would require the Python code to build a tuple from self and
args, which is somewhat inefficient, makes the Python code larger, and in
any case is a change that I don't think people want to make to conform to
a mere convention that arguably doesn't apply in this case.
Or is there somewhere else that you think 'self' should be used?
Josh
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user