The Artima Developer Community
Sponsored Link

Python Answers Forum
C structures in python

1 reply on 1 page. Most recent reply: Oct 27, 2005 1:49 PM by Storm To

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
vidya dyaberi

Posts: 1
Nickname: ccure
Registered: Oct, 2005

C structures in python Posted: Oct 24, 2005 1:15 PM
Reply to this message Reply
Advertisement
I am trying to access C structures in python. Have created an extension of the C using SWIG.
--------------------------------------------------------
sample code for structure VPX_RealPoint
--------------------------------------------------------
class VPX_RealPoint(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, VPX_RealPoint, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, VPX_RealPoint, name)
def __repr__(self):
return "<%s.%s; proxy of C VPX_RealPoint instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
__swig_setmethods__["x"] = VPX_InterApp.VPX_RealPoint_x_set
__swig_getmethods__["x"] = VPX_InterApp.VPX_RealPoint_x_get
if _newclass:x = property(VPX_InterApp.VPX_RealPoint_x_get, VPX_InterApp.VPX_RealPoint_x_set)
__swig_setmethods__["y"] = VPX_InterApp.VPX_RealPoint_y_set
__swig_getmethods__["y"] = VPX_InterApp.VPX_RealPoint_y_get
if _newclass:y = property(VPX_InterApp.VPX_RealPoint_y_get, VPX_InterApp.VPX_RealPoint_y_set)
def __init__(self, *args):
_swig_setattr(self, VPX_RealPoint, 'this', VPX_InterApp.new_VPX_RealPoint(*args))
_swig_setattr(self, VPX_RealPoint, 'thisown', 1)
def __del__(self, destroy=VPX_InterApp.delete_VPX_RealPoint):
try:
if self.thisown: destroy(self)
except: pass


class VPX_RealPointPtr(VPX_RealPoint):
def __init__(self, this):
_swig_setattr(self, VPX_RealPoint, 'this', this)
if not hasattr(self,"thisown"): _swig_setattr(self, VPX_RealPoint, 'thisown', 0)
_swig_setattr(self, VPX_RealPoint,self.__class__,VPX_RealPoint)
VPX_InterApp.VPX_RealPoint_swigregi ster(VPX_RealPointPtr)
//------------------------------------------------------- --

Now how do I access the structure. SWIG example says

import test
RT=test.VPX_RealPoint()

however the above gives me an error
Attribute error: 'module' object has no attribute 'VPX_RealPoint'

Could anyone tell me how to proceed?
Thanks in advance
CCure


Storm To

Posts: 5
Nickname: storm
Registered: Oct, 2005

Re: C structures in python Posted: Oct 27, 2005 1:49 PM
Reply to this message Reply
I am new to Python but here's a suggestion.

You may need to have def __init__(self) like you do in class VPX_RealPointPtr() in order to create a new instance of an object.

Also instead of using SWIG try using BOOST
www.boost.org/libs/python/doc/

Flat View: This topic has 1 reply on 1 page
Topic: calling windows dlls from python Previous Topic   Next Topic Topic: Log Console output

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use