473,698 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

extending: new type instance

I'm writing my own (list-like) type in C. It is implementing
a Sequence Protocol. In 'sq_slice' method I would like to return
a new instance of my class/type.

How do I create (and initialize) an instance of a given
PyTypeObject MyType ?

I have tried to provide (PyObject *)&MyType as 'class' argument to:

PyInstance_New( PyObject *class, PyObject *arg, PyObject *kw)

It failed the PyClass_Check.

I have also found a couple of PyObject_New functions which accept
PyTypeObject as an argument. They look very low-level and obviously
don't call __init__. Should I do it myself manualy ?

BranoZ

Aug 16 '05 #1
2 1753
"BranoZ" <za********@gma il.com> writes:
I'm writing my own (list-like) type in C. It is implementing
a Sequence Protocol. In 'sq_slice' method I would like to return
a new instance of my class/type.

How do I create (and initialize) an instance of a given
PyTypeObject MyType ?

I have tried to provide (PyObject *)&MyType as 'class' argument to:

PyInstance_New( PyObject *class, PyObject *arg, PyObject *kw)

It failed the PyClass_Check.

I have also found a couple of PyObject_New functions which accept
PyTypeObject as an argument. They look very low-level and obviously
don't call __init__. Should I do it myself manualy ?


PyObject_New is the usual way, although there are others --
MyType.tp_new, PyObject_Call ...

Cheers,
mwh

--
81. In computing, turning the obvious into the useful is a living
definition of the word "frustratio n".
-- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html
Aug 17 '05 #2
Michael Hudson wrote:
PyObject_New is the usual way, although there are others --
Thanks for an answer !
MyType.tp_new, PyObject_Call ...


Does this mean, that I can call my newly defined
MyType_new, MyType_init directly ??

I was afraid that Python might do some pretty important
housekeeping stuff around them.

BranoZ

Aug 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5615
by: NadaHombre | last post by:
Hello, If I want to make a class which is a stack of objects of some specific type (not just "Objects"), what is the best way to do it? I wonder if there is some generally accepted "best" way to do this, because it must come up a lot. I personally create a new class which mimics all the methods of java.util.Stack , and keeps a java.util.Stack as a private instance variable. The new class changes the return types of pop and peek and...
5
5901
by: Casper B | last post by:
Since I am only able to pass simple beans around using my Web Service framework, I wonder how to incorporate business logic around these beans. My idea was to let my Beans be the base class and simply extend these with more sophisticated classes with the nessesary business logic inside. However, when I do a cast from MyObjectBean to MyObject I get a ClassCastException. Is it not possible to cast in this direction? public class...
3
3502
by: Lars Moastuen | last post by:
Im trying to extend a class written in C++ in Python and use this extended class in a C++ call... I made an example to clarify: -- Foo.h -- #ifndef FOO_H #define FOO_H #include <iostream> using namespace std;
5
3827
by: vbgunz | last post by:
Hello everyone. I own two books. Learning Python and Python in a nutshell. When cross referencing the two books to try and clarify the ideas behind extending methods and delegates, this is where confusion veered it's ugly head :( Learning Python explains on page 324: Class Interface Techniques (21.3.3 in the ebook) the following is an extender method. ''' #################################### '''
13
2563
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){}, my_meth2: function(){} }); to define new methods on the MyObj prototype object. Object.extend
9
2183
by: Robert | last post by:
Hi, I thought it would be a good idea to make specialised error objects. So I did something like this: function IndexOutOfBoundsException(message) { Error.call(this, message); }
4
2270
by: Ian Richardson | last post by:
Hi, The function I've put together below is a rough idea to extend a SELECT list, starting from: <body> <form name="bambam"> <select id="fred"> <option value="1">1</option> <option value="2">2</option>
3
3675
by: katis | last post by:
Hi all :) Is it posible in xsd to change only minOccurs value of element in complex type by extending this type? The problem I'm trying to solve is this: I have two complex types - "TextField" and "FileChooser". Here is definition of "TextField" <xsd:complexType name="TextField">
7
3384
by: Maximus Decimus | last post by:
HI all, I am using python v2.5 and I am an amateur working on python. I am extending python for my research work and would like some help and guidance w.r.t this matter from you experienced python developers. II want to add some more KEYWORDS and DATATYPES into the python script apart from the existing ones. It would be really great if anybody could guide me as which files and
0
8600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7711
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5859
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3038
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2322
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1997
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.