freelanceprogrammers.org Forum Index » Delphi

VarIsPythonClass doesn`t work fine for new-style python clas


View user's profile Post To page top
daydaysy Posted: Sat May 21, 2005 1:56 pm


Joined: 21 May 2005

Posts: 13
VarIsPythonClass doesn`t work fine for new-style python clas
In procedure btnTestObjectsClick of demo25,
After I changed "class Foo:" into "class Foo(object):",
the testobject will fail at this line:
Assert( VarIsPythonClass(_main.Foo) );
Is this because we can`t access new-style calsses from
delphi?

Thanks in advance.
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Sat May 21, 2005 9:49 pm


Joined: 29 Apr 2005

Posts: 103
VarIsPythonClass doesn`t work fine for new-style python clas
Hi,

> In procedure btnTestObjectsClick of demo25, After I changed "class
> Foo:" into "class Foo(object):", the testobject will fail at this
> line:
> Assert( VarIsPythonClass(_main.Foo) ); Is this because we can`t
> access new-style calsses from delphi?

No this is a bug of P4D and is not related to Delphi. The function
VarIsPythonClass simply checks that the python object has a PyClass_Type
type, which is false with new-style python classes.
I will fix it in the next release, thanks for reporting it!

In the mean time, as a workaround, you can use the python inspect module
like this:

If Boolean(Import(`inspect`).isclass(myClass)) then...

Bye,

Morgan
Reply with quote
Send private message
View user's profile Post To page top
daydaysy Posted: Sun May 22, 2005 10:01 am


Joined: 21 May 2005

Posts: 13
VarIsPythonClass doesn`t work fine for new-style python clas
Thank you so much~

And I want to say that P4D is magic!
But if more docs can be found, p4d will be perfect.

--- In pythonfordelphi@yahoogroups.com, "Morgan Martinet" <yahoo@m...>
wrote:
> Hi,
>
> > In procedure btnTestObjectsClick of demo25, After I changed "class
> > Foo:" into "class Foo(object):", the testobject will fail at this
> > line:
> > Assert( VarIsPythonClass(_main.Foo) ); Is this because we can`t
> > access new-style calsses from delphi?
>
> No this is a bug of P4D and is not related to Delphi. The function
> VarIsPythonClass simply checks that the python object has a PyClass_Type
> type, which is false with new-style python classes.
> I will fix it in the next release, thanks for reporting it!
>
> In the mean time, as a workaround, you can use the python inspect module
> like this:
>
> If Boolean(Import(`inspect`).isclass(myClass)) then...
>
> Bye,
>
> Morgan
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help