Re: How to call a Python Class?

2016-05-03 Thread Ben Finney
David Shi via Python-list writes: > I found a Python class within an Open Source software. > I would like to use it in my own Python script. > I tried to import it, but I got following message. Your text is mangled in transit. Please post only plain text messages (avoid HTML or ot

Re: How to call a Python Class?

2016-05-03 Thread Chris Angelico
On Wed, May 4, 2016 at 8:56 AM, David Shi via Python-list wrote: > I found a Python class within an Open Source software. > I would like to use it in my own Python script. > I tried to import it, but I got following message. > from intersection import *Traceback (most recent call

How to call a Python Class?

2016-05-03 Thread David Shi via Python-list
I found a Python class within an Open Source software. I would like to use it in my own Python script. I tried to import it, but I got following message. from intersection import *Traceback (most recent call last):  File "", line 1, in     from intersection import *ImportError: bad ma

Re: How to create an instance of a python class from C++

2014-03-12 Thread Stefan Behnel
Barry Scott, 11.03.2014 22:37: > On 5 Mar 2014, at 00:14, Bill wrote: >> I can't figure out how to create an instance >> of a python class from 'C++': > > Why not use pycxx from http://sourceforge.net/projects/cxx/? > > This lib does all the heavy li

Re: How to create an instance of a python class from C++

2014-03-11 Thread Barry Scott
On 5 Mar 2014, at 00:14, Bill wrote: > Hello: > > I can't figure out how to create an instance > of a python class from 'C++': > Why not use pycxx from http://sourceforge.net/projects/cxx/? This lib does all the heavy lifting for you for both python2 and

Re: How to create an instance of a python class from C++

2014-03-05 Thread Gene Heskett
On Wednesday 05 March 2014 17:09:53 Grant Edwards did opine: > On 2014-03-05, Alister wrote: > >>> Why are you creating an ABC? > >> > >> Because it was the first binary computer that did calculations with > >> electronic switching elements (gates), and it would be really cool to > >> have one!

Re: How to create an instance of a python class from C++

2014-03-05 Thread Grant Edwards
On 2014-03-05, Alister wrote: >> >>> Why are you creating an ABC? >> >> Because it was the first binary computer that did calculations with >> electronic switching elements (gates), and it would be really cool to >> have one! The ABC also pioneered the use of capciators as regenerative >> storage

Re: How to create an instance of a python class from C++

2014-03-05 Thread Alister
On Wed, 05 Mar 2014 16:08:00 +, Grant Edwards wrote: > On 2014-03-05, Ian Kelly wrote: >> On Tue, Mar 4, 2014 at 5:14 PM, Bill wrote: >>> Hello: >>> >>> I can't figure out how to create an instance of a python class from >>> 'C++'

Re: How to create an instance of a python class from C++

2014-03-05 Thread Grant Edwards
On 2014-03-05, Ian Kelly wrote: > On Tue, Mar 4, 2014 at 5:14 PM, Bill wrote: >> Hello: >> >> I can't figure out how to create an instance >> of a python class from 'C++': >> >> ( I am relatively new to Python so excuse some of the fol

Re: How to create an instance of a python class from C++

2014-03-05 Thread Bill
> > So far, so good. The object that was passed in was the "Derived" > class object. Since you presumably only want class objects to be > passed in, you might want to check that here using PyType_Check. > Yes. Will do. > > > PyTypeObject *typ = class_decl->ob_type; > > In Python, y

Re: How to create an instance of a python class from C++

2014-03-04 Thread Ian Kelly
On Tue, Mar 4, 2014 at 5:14 PM, Bill wrote: > Hello: > > I can't figure out how to create an instance > of a python class from 'C++': > > ( I am relatively new to Python so excuse some of > the following. ) > > In a .py file I create an ABC and then s

How to create an instance of a python class from C++

2014-03-04 Thread Bill
Hello: I can't figure out how to create an instance of a python class from 'C++': ( I am relatively new to Python so excuse some of the following. ) In a .py file I create an ABC and then specialize it: from MyMod import * from abc import ABCMeta, abstractmethod

Re: A Python class

2012-09-06 Thread Chris Angelico
course python' for taught courses. > At least 2 of MIT's self-guided OpenCourseWare courses use Python. Note this subtle distinction. A Python course will (theoretically, at least!) teach you how to write Python code. A Python class is a collection of methods and stuff. A trivial

Re: A Python class

2012-09-06 Thread Terry Reedy
On 9/6/2012 11:08 AM, Yves S. Garret wrote: I'd like to know if there are any online Python classes offered online from reliable institutions that you would recommend. Google 'online programming course python' for taught courses. At least 2 of MIT's self-guided OpenCourseWare courses use P

Re: Instantiate a python class object in C

2012-03-14 Thread Dids
Ok, I have it :) PyImport_Import , PyModule_GetDict, PyDict_GetItemString and PyObject_CallObject Need to take a second look at cython when I have a spare cycle or 2. Thanks for the the tip :) A+ Dids, -- http://mail.python.org/mailman/listinfo/python-list

Re: Instantiate a python class object in C

2012-03-14 Thread Stefan Behnel
Dids, 14.03.2012 14:46: > Apologies if this was asked before, I couldn't find anything. > > I have a class defined in a python file: > for example: > > class demo: > [ class definition goes here] > > I'm writing a C extension. > In the first function, I take an instance of the "demo" class

Instantiate a python class object in C

2012-03-14 Thread Dids
Hi, Apologies if this was asked before, I couldn't find anything. I have a class defined in a python file: for example: class demo: [ class definition goes here] I'm writing a C extension. In the first function, I take an instance of the "demo" class and do my magic. It's working, all is

Re: Storing a C pointer in a Python class instance

2009-10-06 Thread lallous
"Carl Banks" wrote in message news:d50bba1e-b272-4e39-8a58-377531278...@z4g2000prh.googlegroups.com... On Sep 30, 5:24 am, "lallous" wrote: Hello After using the PyCObject, I cannot pickle the class anymore. Any simple solution to this problem? (or resorting to __reduce__ is the only soluti

Re: Storing a C pointer in a Python class instance

2009-09-30 Thread sturlamolden
cator is as reliable as a custom > type's tp_dealloc. You are right. I did not look at the PyCObject_* API close enough. I thought of wrapping the CObject with a Python class, and calling the destructor from __del__. That would be less reliable. S.M. -- http://mail.python.org/mailman/listinfo/python-list

Re: Storing a C pointer in a Python class instance

2009-09-30 Thread Carl Banks
On Sep 29, 11:16 am, sturlamolden wrote: > On 29 Sep, 19:11, Carl Banks wrote: > > > CObjects can be passed a C function as a deallocator; this should work > > as reliably as a custom class deallocator. > > Except that __del__ prevents cyclic GC. You are mistaken on two counts. First of all, a

Re: Storing a C pointer in a Python class instance

2009-09-30 Thread Carl Banks
On Sep 30, 5:24 am, "lallous" wrote: > Hello > > After using the PyCObject, I cannot pickle the class anymore. > Any simple solution to this problem? (or resorting to __reduce__ is the only > solution?) You can't pickle a CObject, you'd have to create a custom type (one that implements one of th

Re: Storing a C pointer in a Python class instance

2009-09-30 Thread lallous
Hello After using the PyCObject, I cannot pickle the class anymore. Any simple solution to this problem? (or resorting to __reduce__ is the only solution?) Thanks, Elias "Falcolas" wrote in message news:9d3790aa-f7d9-4bb5-a81f-5428b2d60...@v25g2000yqk.googlegroups.com... On Sep 29, 2:27 am

Re: Storing a C pointer in a Python class instance

2009-09-30 Thread lallous
Thanks everyone. Finally, I used Falcolas suggestion and took into consideration sturlamolden's comments. Regards, Elias "lallous" wrote in message news:h9sgcn$iv...@aioe.org... Hello From my C extension module I want to store a C pointer in a given PyObject. The only way I figure how to

Re: Storing a C pointer in a Python class instance

2009-09-29 Thread sturlamolden
On 29 Sep, 19:11, Carl Banks wrote: > CObjects can be passed a C function as a deallocator; this should work > as reliably as a custom class deallocator. > > Carl Banks Except that __del__ prevents cyclic GC. -- http://mail.python.org/mailman/listinfo/python-list

Re: Storing a C pointer in a Python class instance

2009-09-29 Thread Carl Banks
On Sep 29, 9:42 am, sturlamolden wrote: > You can use PyCObject, or write your own extension type that wraps the > pointer (very easy to to with Cython or Pyrex). The advantage of using > an extension type is you have a guarantee from Python on the > deallocator method being called (cdef __dealloc

Re: Storing a C pointer in a Python class instance

2009-09-29 Thread sturlamolden
cdef __dealloc__ in Cython). If the pointer references a resource that needs to be closed, this is safer than using a __del__ method in a Python class. -- http://mail.python.org/mailman/listinfo/python-list

Re: Storing a C pointer in a Python class instance

2009-09-29 Thread Falcolas
On Sep 29, 2:27 am, "lallous" wrote: > Hello > > From my C extension module I want to store a C pointer in a given PyObject. > > The only way I figure how to do it is to use Py_BuildValues and store the > poiner casted to Py_ssize_t, thus: > > Py_BuildValues("n", (Py_ssize_t)my_ptr) > > Can it be

Storing a C pointer in a Python class instance

2009-09-29 Thread lallous
Hello From my C extension module I want to store a C pointer in a given PyObject. The only way I figure how to do it is to use Py_BuildValues and store the poiner casted to Py_ssize_t, thus: Py_BuildValues("n", (Py_ssize_t)my_ptr) Can it be done differently? Regards, Elias -- http://ma

Re: include a python class in another python script.

2006-08-15 Thread danielx
KraftDiner wrote: > I have a class that is defined in a file called MyClass.py > > How do I use that class in another python script.. > import MyClass ? (Does it need to be in a specific location?) MyClass.py has to be on your "python path". Your python path is a list of directories python will

Re: include a python class in another python script.

2006-08-15 Thread [EMAIL PROTECTED]
KraftDiner wrote: > I have a class that is defined in a file called MyClass.py > > How do I use that class in another python script.. > import MyClass ? (Does it need to be in a specific location?) Same directory as the script that's importing it, or in the PYTHONPATH. import sys print sys.path

include a python class in another python script.

2006-08-15 Thread KraftDiner
I have a class that is defined in a file called MyClass.py How do I use that class in another python script.. import MyClass ? (Does it need to be in a specific location?) -- http://mail.python.org/mailman/listinfo/python-list

Re: using vim as a python class/module/function etc.. browser

2006-04-11 Thread Chris Jones
Daniel Nogradi wrote: Of course, modern versions of Exuberant Ctags also support Python, too. >>> >>>I apt-installed this package but the man page is rather intimidating so >>>I thought I might as well make sure I was going in the right direction. >> >>You will probably want to read the vim doc

Re: using vim as a python class/module/function etc.. browser

2006-04-11 Thread Daniel Nogradi
> >>Of course, modern versions of Exuberant Ctags also support Python, too. > > > > I apt-installed this package but the man page is rather intimidating so > > I thought I might as well make sure I was going in the right direction. > > You will probably want to read the vim documentation on how to

Re: using vim as a python class/module/function etc.. browser

2006-04-10 Thread Robert Kern
Chris Jones wrote: > Robert Kern wrote: >>Of course, modern versions of Exuberant Ctags also support Python, too. > > I apt-installed this package but the man page is rather intimidating so > I thought I might as well make sure I was going in the right direction. You will probably want to read

Re: using vim as a python class/module/function etc.. browser

2006-04-10 Thread Chris Jones
Robert Kern wrote: > Chris Jones wrote: > >>I'm trying to make sense of a python program and was wondering if vim >>has any python-oriented functionalities (apart from syntax highlighting) >>that would make it somewhat easier to browse the source code. >> >>What I had in mind is something that w

Re: using vim as a python class/module/function etc.. browser

2006-04-10 Thread Robert Kern
Chris Jones wrote: > I'm trying to make sense of a python program and was wondering if vim > has any python-oriented functionalities (apart from syntax highlighting) > that would make it somewhat easier to browse the source code. > > What I had in mind is something that would let me use CTRL+] t

using vim as a python class/module/function etc.. browser

2006-04-10 Thread Chris Jones
I'm trying to make sense of a python program and was wondering if vim has any python-oriented functionalities (apart from syntax highlighting) that would make it somewhat easier to browse the source code. What I had in mind is something that would let me use CTRL+] to automatically display what