Re: Embedding Python crash on PyTuple_New

2021-11-24 Thread MRAB
On 2021-11-24 07:59, Arnaud Loonstra wrote: On 24-11-2021 01:46, MRAB wrote: On 2021-11-23 20:25, Arnaud Loonstra wrote: On 23-11-2021 18:31, MRAB wrote: On 2021-11-23 16:04, Arnaud Loonstra wrote: On 23-11-2021 16:37, MRAB wrote: On 2021-11-23 15:17, MRAB wrote: On 2021-11-23 14:44, Arnau

Re: Embedding Python crash on PyTuple_New

2021-11-24 Thread Arnaud Loonstra
On 24-11-2021 01:46, MRAB wrote: On 2021-11-23 20:25, Arnaud Loonstra wrote: On 23-11-2021 18:31, MRAB wrote: On 2021-11-23 16:04, Arnaud Loonstra wrote: On 23-11-2021 16:37, MRAB wrote: On 2021-11-23 15:17, MRAB wrote: On 2021-11-23 14:44, Arnaud Loonstra wrote: On 23-11-2021 15:34, MRAB

Re: Embedding Python crash on PyTuple_New

2021-11-23 Thread MRAB
On 2021-11-23 20:25, Arnaud Loonstra wrote: On 23-11-2021 18:31, MRAB wrote: On 2021-11-23 16:04, Arnaud Loonstra wrote: On 23-11-2021 16:37, MRAB wrote: On 2021-11-23 15:17, MRAB wrote: On 2021-11-23 14:44, Arnaud Loonstra wrote: On 23-11-2021 15:34, MRAB wrote: On 2021-11-23 12:07, Arnaud

Re: Embedding Python crash on PyTuple_New

2021-11-23 Thread Arnaud Loonstra
On 23-11-2021 18:31, MRAB wrote: On 2021-11-23 16:04, Arnaud Loonstra wrote: On 23-11-2021 16:37, MRAB wrote: On 2021-11-23 15:17, MRAB wrote: On 2021-11-23 14:44, Arnaud Loonstra wrote: On 23-11-2021 15:34, MRAB wrote: On 2021-11-23 12:07, Arnaud Loonstra wrote: Hi, I've got Python embedd

Re: Embedding Python crash on PyTuple_New

2021-11-23 Thread MRAB
On 2021-11-23 17:31, MRAB wrote: On 2021-11-23 16:04, Arnaud Loonstra wrote: [snip] I would turn my attention to s_py_zosc function but I'm not sure. Since the errors are GC related it could caused anywhere? Basically, yes, but I won't be surprised if it was due to too few INCREFs or too man

Re: Embedding Python crash on PyTuple_New

2021-11-23 Thread MRAB
On 2021-11-23 16:04, Arnaud Loonstra wrote: On 23-11-2021 16:37, MRAB wrote: On 2021-11-23 15:17, MRAB wrote: On 2021-11-23 14:44, Arnaud Loonstra wrote: On 23-11-2021 15:34, MRAB wrote: On 2021-11-23 12:07, Arnaud Loonstra wrote: Hi, I've got Python embedded successfully in a program up un

Re: Embedding Python crash on PyTuple_New

2021-11-23 Thread Arnaud Loonstra
On 23-11-2021 16:37, MRAB wrote: On 2021-11-23 15:17, MRAB wrote: On 2021-11-23 14:44, Arnaud Loonstra wrote: On 23-11-2021 15:34, MRAB wrote: On 2021-11-23 12:07, Arnaud Loonstra wrote: Hi, I've got Python embedded successfully in a program up until now as I'm now running into weird GC rela

Re: Embedding Python crash on PyTuple_New

2021-11-23 Thread MRAB
On 2021-11-23 15:17, MRAB wrote: On 2021-11-23 14:44, Arnaud Loonstra wrote: On 23-11-2021 15:34, MRAB wrote: On 2021-11-23 12:07, Arnaud Loonstra wrote: Hi, I've got Python embedded successfully in a program up until now as I'm now running into weird GC related segfaults. I'm currently tryin

Re: Embedding Python crash on PyTuple_New

2021-11-23 Thread MRAB
On 2021-11-23 14:44, Arnaud Loonstra wrote: On 23-11-2021 15:34, MRAB wrote: On 2021-11-23 12:07, Arnaud Loonstra wrote: Hi, I've got Python embedded successfully in a program up until now as I'm now running into weird GC related segfaults. I'm currently trying to debug this but my understandi

Re: Embedding Python crash on PyTuple_New

2021-11-23 Thread Arnaud Loonstra
On 23-11-2021 15:34, MRAB wrote: On 2021-11-23 12:07, Arnaud Loonstra wrote: Hi, I've got Python embedded successfully in a program up until now as I'm now running into weird GC related segfaults. I'm currently trying to debug this but my understanding of CPython limits me here. I'm creating a

Re: Embedding Python crash on PyTuple_New

2021-11-23 Thread MRAB
On 2021-11-23 12:07, Arnaud Loonstra wrote: Hi, I've got Python embedded successfully in a program up until now as I'm now running into weird GC related segfaults. I'm currently trying to debug this but my understanding of CPython limits me here. I'm creating a Tuple in C but it crashes on crea

Re: Embedding Python crash on PyTuple_New

2021-11-23 Thread Arnaud Loonstra
On 23-11-2021 13:07, Arnaud Loonstra wrote: Hi, I've got Python embedded successfully in a program up until now as I'm now running into weird GC related segfaults. I'm currently trying to debug this but my understanding of CPython limits me here. I'm creating a Tuple in C but it crashes on c

Re: Embedding Python

2021-06-02 Thread Chris Angelico
On Thu, Jun 3, 2021 at 4:05 AM Faraaz Mohammed wrote: > > On Tuesday, 1 July 2008 at 21:37:49 UTC+5:30, mk wrote: > > Carsten Haese wrote: > > > python_code is a C string containing the raw bytes from your pyc file. > > > Casting that to a PyObject pointer will not magically transform it into > >

Re: Embedding Python

2021-06-02 Thread Faraaz Mohammed
On Tuesday, 1 July 2008 at 21:37:49 UTC+5:30, mk wrote: > Carsten Haese wrote: > > python_code is a C string containing the raw bytes from your pyc file. > > Casting that to a PyObject pointer will not magically transform it into > > a Python code object. > well yeah, I kind of didn't think that

Re: Embedding Python in C

2019-07-24 Thread Jesse Ibarra
On Tuesday, July 23, 2019 at 2:20:45 PM UTC-6, Stefan Behnel wrote: > Jesse Ibarra schrieb am 22.07.19 um 18:12: > > On Saturday, July 20, 2019 at 1:11:51 PM UTC-6, Stefan Behnel wrote: > >> Jesse Ibarra schrieb am 20.07.19 um 04:12: > >>> Sorry, I am not understanding. Smalltlak VW 8.3 does not su

Re: Embedding Python in C

2019-07-23 Thread Stefan Behnel
Jesse Ibarra schrieb am 22.07.19 um 18:12: > On Saturday, July 20, 2019 at 1:11:51 PM UTC-6, Stefan Behnel wrote: >> Jesse Ibarra schrieb am 20.07.19 um 04:12: >>> Sorry, I am not understanding. Smalltlak VW 8.3 does not support Python. >>> I can only call Pyhton code through C/Python API. >> >> Ok

Re: Embedding Python in C

2019-07-22 Thread Jesse Ibarra
On Saturday, July 20, 2019 at 1:11:51 PM UTC-6, Stefan Behnel wrote: > Jesse Ibarra schrieb am 20.07.19 um 04:12: > > Sorry, I am not understanding. Smalltlak VW 8.3 does not support Python. > > I can only call Pyhton code through C/Python API. > > Ok, but that doesn't mean you need to write code

Re: Embedding Python in C

2019-07-20 Thread Stefan Behnel
Jesse Ibarra schrieb am 20.07.19 um 04:12: > Sorry, I am not understanding. Smalltlak VW 8.3 does not support Python. > I can only call Pyhton code through C/Python API. Ok, but that doesn't mean you need to write code that uses the C-API of Python. All you need to do is: 1) Start up a CPython ru

Re: Embedding Python in C

2019-07-19 Thread dieter
Jesse Ibarra writes: > ... > Now ,I need to bring in shared libraries using C/Python API using Smalltalk. > It seems like I can't directly bring in C shared libraries (.so files). > PROBLEM. With Python, you typically do not load ("bring in") shared libraries explicitly; instead, you simply imp

Re: Embedding Python in C

2019-07-19 Thread Jesse Ibarra
Sorry, I am not understanding. Smalltlak VW 8.3 does not support Python. I can only call Pyhton code through C/Python API. -- https://mail.python.org/mailman/listinfo/python-list

Re: Embedding Python in C

2019-07-19 Thread Stefan Behnel
Jesse Ibarra schrieb am 17.07.19 um 20:39: > My options seem rather limited, I need to make a Pipeline from > (Smalltalk -> C -> Python) then go back (Smalltalk <- C <- Python). > Since Smalltalk does not support Python directly I have to settle with > the C/Python API > (https://docs.python.org/3.

Re: Embedding Python in C

2019-07-19 Thread Christian Gollwitzer
Am 19.07.19 um 16:26 schrieb Jesse Ibarra: On Friday, July 19, 2019 at 8:17:43 AM UTC-6, Chris Angelico wrote: On Sat, Jul 20, 2019 at 12:16 AM Jesse Ibarra wrote: On Thursday, July 18, 2019 at 2:01:39 PM UTC-6, Chris Angelico wrote: On Fri, Jul 19, 2019 at 5:51 AM Christian Gollwitzer wrot

Re: Embedding Python in C

2019-07-19 Thread Jesse Ibarra
On Friday, July 19, 2019 at 8:17:43 AM UTC-6, Chris Angelico wrote: > On Sat, Jul 20, 2019 at 12:16 AM Jesse Ibarra > wrote: > > > > On Thursday, July 18, 2019 at 2:01:39 PM UTC-6, Chris Angelico wrote: > > > On Fri, Jul 19, 2019 at 5:51 AM Christian Gollwitzer > > > wrote: > > > > Once you can

Re: Embedding Python in C

2019-07-19 Thread Jesse Ibarra
On Thursday, July 18, 2019 at 1:46:05 PM UTC-6, Christian Gollwitzer wrote: > Am 18.07.19 um 16:18 schrieb Jesse Ibarra: > > On Wednesday, July 17, 2019 at 2:20:51 PM UTC-6, Christian Gollwitzer wrote: > >> What level of integration do you want to achieve? Do you want > >> > >> a) to call Python fu

Re: Embedding Python in C

2019-07-19 Thread Chris Angelico
On Sat, Jul 20, 2019 at 12:16 AM Jesse Ibarra wrote: > > On Thursday, July 18, 2019 at 2:01:39 PM UTC-6, Chris Angelico wrote: > > On Fri, Jul 19, 2019 at 5:51 AM Christian Gollwitzer > > wrote: > > > Once you can do this, you can proceed to call a Python function, which > > > in C means that yo

Re: Embedding Python in C

2019-07-19 Thread Jesse Ibarra
On Thursday, July 18, 2019 at 2:01:39 PM UTC-6, Chris Angelico wrote: > On Fri, Jul 19, 2019 at 5:51 AM Christian Gollwitzer wrote: > > Once you can do this, you can proceed to call a Python function, which > > in C means that you invoke the function PyObject_CallObject(). A basic > > example is s

Re: Embedding Python in C

2019-07-18 Thread Chris Angelico
On Fri, Jul 19, 2019 at 5:51 AM Christian Gollwitzer wrote: > Once you can do this, you can proceed to call a Python function, which > in C means that you invoke the function PyObject_CallObject(). A basic > example is shown here: > > https://docs.python.org/2/extending/embedding.html#pure-embeddi

Re: Embedding Python in C

2019-07-18 Thread Christian Gollwitzer
Am 18.07.19 um 16:18 schrieb Jesse Ibarra: On Wednesday, July 17, 2019 at 2:20:51 PM UTC-6, Christian Gollwitzer wrote: What level of integration do you want to achieve? Do you want a) to call Python functions from Smalltalk b) call Smalltalk functions from Python c) pass callbacks around, e.g.

Re: Embedding Python in C

2019-07-18 Thread Jesse Ibarra
On Wednesday, July 17, 2019 at 2:20:51 PM UTC-6, Christian Gollwitzer wrote: > Am 17.07.19 um 20:39 schrieb Jesse Ibarra: > > My options seem rather limited, I need to make a Pipeline from (Smalltalk > > -> C -> Python) then go back (Smalltalk <- C <- Python). Since Smalltalk > > does not support

Re: Embedding Python in C

2019-07-18 Thread Barry Scott
> On 17 Jul 2019, at 19:39, Jesse Ibarra wrote: > > On Wednesday, July 17, 2019 at 11:55:28 AM UTC-6, Barry Scott wrote: >>> On 17 Jul 2019, at 16:57, wrote: >>> >>> I am using Python3.6: >>> >>> [jibarra@redsky ~]$ python3.6 >>> Python 3.6.8 (default, Apr 25 2019, 21:02:35) >>> [GCC 4.8.5

Re: Embedding Python in C

2019-07-17 Thread dieter
Jesse Ibarra writes: > ... > My options seem rather limited, I need to make a Pipeline from (Smalltalk -> > C -> Python) then go back (Smalltalk <- C <- Python). Since Smalltalk does > not support Python directly I have to settle with the C/Python API > (https://docs.python.org/3.6/extending/em

Re: Embedding Python in C

2019-07-17 Thread Christian Gollwitzer
Am 17.07.19 um 20:39 schrieb Jesse Ibarra: My options seem rather limited, I need to make a Pipeline from (Smalltalk -> C -> Python) then go back (Smalltalk <- C <- Python). Since Smalltalk does not support Python directly I have to settle with the C/Python API (https://docs.python.org/3.6/ext

Re: Embedding Python in C

2019-07-17 Thread Jesse Ibarra
On Wednesday, July 17, 2019 at 11:55:28 AM UTC-6, Barry Scott wrote: > > On 17 Jul 2019, at 16:57, wrote: > > > > I am using Python3.6: > > > > [jibarra@redsky ~]$ python3.6 > > Python 3.6.8 (default, Apr 25 2019, 21:02:35) > > [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux > > Type "help", "

Re: Embedding Python in C

2019-07-17 Thread Barry Scott
> On 17 Jul 2019, at 16:57, jesse.ibarra.1...@gmail.com wrote: > > I am using Python3.6: > > [jibarra@redsky ~]$ python3.6 > Python 3.6.8 (default, Apr 25 2019, 21:02:35) > [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux > Type "help", "copyright", "credits" or "license" for more information

Re: embedding python - PyImport_ImportModule returns null

2019-03-28 Thread babita . trial
If nothing works mentioned above, please try building your application from common path. ( not from c:\users\ ). While working on office environment, this has impact. -- https://mail.python.org/mailman/listinfo/python-list

Re: Embedding Python into C set up issues

2016-03-14 Thread robert . snoeberger
> > However, I am having great trouble getting Py_Initialize() to work in the > both CDT and Visual Studio 2015. I have as a starting point a simple C > program that prints hello world then calls py_initialize and then prints > another line of text to the screen. Calling Py_initialize causes th

Re: Embedding Python in a shell script

2011-06-17 Thread Jason Friedman
Thank you, everyone, for your suggestions. I'll try them all and decide which I like best. -- http://mail.python.org/mailman/listinfo/python-list

Re: Embedding Python in a shell script

2011-06-17 Thread Timo Lindemann
On Fri, 17 Jun 2011 22:15:57 +0200, Hans Mulder said: > On 17/06/11 19:47:50, Timo Lindemann wrote: >> On Fri, 17 Jun 2011 00:57:25 +, Jason Friedman said: >> >> >> >>> but for various reasons I want a single script. Any alternatives? >> >> you can use a here document like this: > That does n

Re: Embedding Python in a shell script

2011-06-17 Thread Hans Mulder
On 17/06/11 19:47:50, Timo Lindemann wrote: On Fri, 17 Jun 2011 00:57:25 +, Jason Friedman said: but for various reasons I want a single script. Any alternatives? you can use a here document like this: #! /bin/bash /usr/bin/python2<< EOPYTHON def hello(): print("Hello, Worl

Re: Embedding Python in a shell script

2011-06-17 Thread Timo Lindemann
On Fri, 17 Jun 2011 00:57:25 +, Jason Friedman said: > > but for various reasons I want a single script. Any alternatives? you can use a here document like this: #! /bin/bash /usr/bin/python2 << EOPYTHON def hello(): print("Hello, World"); if __name__ == "__main__": hel

Re: Embedding Python in a shell script

2011-06-17 Thread mg
rusi wrote: > On Jun 17, 6:05 am, Chris Angelico wrote: > >> > Python call becomes.  I'd prefer something like: >> >> #!/bin/bash >> for i in 1 2 3 4; do >>   python -c "if True: > # comfortably indented python code > > Thanks. Nice! You can use bash here document feature, <<-, that strips hea

Re: Embedding Python in a shell script

2011-06-16 Thread rusi
On Jun 17, 6:05 am, Chris Angelico wrote: > > Python call becomes.  I'd prefer something like: > > #!/bin/bash > for i in 1 2 3 4; do >   python -c "if True: # comfortably indented python code Thanks. Nice! -- http://mail.python.org/mailman/listinfo/python-list

Re: Embedding Python in a shell script

2011-06-16 Thread Chris Angelico
On Fri, Jun 17, 2011 at 10:57 AM, Jason Friedman wrote: > The code behaves as I expect and want, but the de-denting of the > Python call is unattractive, especially unattractive the longer the > Python call becomes.  I'd prefer something like: > #!/bin/bash for i in 1 2 3 4; do python -c "if Tr

Re: Embedding Python: estimate size of dict/list

2011-03-28 Thread Michael Hunter
On Mon, Mar 28, 2011 at 4:18 PM, Chris Angelico wrote: [...] > Obviously I could use PyObject_Str() and PyString_Size() to get a > decent figure, but that seems like overkill. > > What I'm hoping for is some simple function that zips through a > complex object and sums its approximate memory usage

Re: Embedding Python: estimate size of dict/list

2011-03-28 Thread Chris Angelico
On Tue, Mar 29, 2011 at 12:03 PM, Jerry Hill wrote: > On Mon, Mar 28, 2011 at 8:26 PM, Chris Angelico wrote: >> Based on the docs and http://code.activestate.com/recipes/577504/ I >> understand that to be non-recursive. I'm guessing then that there >> isn't a recursive version, and that it's best

Re: Embedding Python: estimate size of dict/list

2011-03-28 Thread Jerry Hill
On Mon, Mar 28, 2011 at 8:26 PM, Chris Angelico wrote: > Based on the docs and http://code.activestate.com/recipes/577504/ I > understand that to be non-recursive. I'm guessing then that there > isn't a recursive version, and that it's best to recurse myself? Yes, you're right. I completely miss

Re: Embedding Python: estimate size of dict/list

2011-03-28 Thread Chris Angelico
On Tue, Mar 29, 2011 at 10:56 AM, Jerry Hill wrote: > For python 2.6 and later, sys.getsizeof() will probably do what you > want.  It relies on objects implementing a __sizeof__() method, so > third-party objects may or may not support this, but since you're > looking at dicts and lists, you shoul

Re: Embedding Python: estimate size of dict/list

2011-03-28 Thread Jerry Hill
On Mon, Mar 28, 2011 at 7:18 PM, Chris Angelico wrote: > I have an application that embeds Python to allow third-party > scripting. The Python code returns data to the application in the form > of a list or dictionary, and I'd like to have a quick check on the > size of the outputted object before

Re: Embedding python : can't find encoding error

2011-03-01 Thread swapnil
On Feb 28, 4:57 pm, Mathieu CLERICI wrote: > Hi, > > I'm trying to embed python in a c++ program. > I have compiled python32.lib with msvc 2010 targetting 32bits, i link > it with my program wich is also 32bit. > I get an error when calling Py_Initialize() : "no codec search > functions registered

Re: Embedding python : can't find encoding error

2011-02-28 Thread Mathieu CLERICI
Precisions : I'm trying to embed python 3.2 release. -- http://mail.python.org/mailman/listinfo/python-list

Re: embedding python in macOS 10.6

2010-10-28 Thread Aahz
[posted & e-mailed] In article , tinau...@libero.it wrote: > >i'm trying to embed python in a c++ code.i'm starting with the example in the >tutorial.i've problem with setting up the enveiroment. >I've installed python with the distributed version (i.e., i did not, as a >start, build it myself)

Re: Embedding Python in a C extension

2010-06-03 Thread kai028
Thanks for the reply. I'm checking this out today. On Wed, 2 Jun 2010 22:30:37 -0700 (PDT), Carl Banks wrote: >On Jun 2, 1:46 pm, Paul Grunau wrote: >> I have a problem with embedding Python into a C extension in Windows >> Vista. I have implemented a timer routine in C as an extension, which >>

Re: Embedding Python in a C extension

2010-06-03 Thread kai028
Thanks for the reply. I'm looking into the Global Interpreter Lock today. On Thu, 03 Jun 2010 01:07:39 +0100, MRAB wrote: >p...@mail.python.org wrote: >> I have a problem with embedding Python into a C extension in Windows >> Vista. I have implemented a timer routine in C as an extension, which

Re: Embedding Python in a C extension

2010-06-02 Thread Carl Banks
On Jun 2, 1:46 pm, Paul Grunau wrote: > I have a problem with embedding Python into a C extension in Windows > Vista. I have implemented a timer routine in C as an extension, which > I can import into Python 2.6.5 and run. Each timer interval, the > extension calls a C CALLBACK function. I want to

Re: Embedding Python in a C extension

2010-06-02 Thread MRAB
p...@mail.python.org wrote: I have a problem with embedding Python into a C extension in Windows Vista. I have implemented a timer routine in C as an extension, which I can import into Python 2.6.5 and run. Each timer interval, the extension calls a C CALLBACK function. I want to be able to have

Re: Embedding Python. But not so easy.

2009-01-20 Thread Diez B. Roggisch
> 1) Threads: the simulation is going to be run in a very parallel > environment with several CPUs and > http://docs.python.org/c-api/init.html#thread-state-and- > the-global-interpreter-lock there is a global lock mentioned. Does that > mean that the python code can not benefit from this ? Not if

Re: embedding python in wxpython

2008-12-30 Thread Mike Driscoll
On Dec 30, 3:41 pm, Steve Holden wrote: > 5lvqbw...@sneakemail.com wrote: > > Hi, I've looked around for a way to allow a python console from within > > a wxPython application, but have only found stuff on embedded/ > > extending python with C/C++ or wxWidgets in C++, but not wxPython. > > > Is th

Re: embedding python in wxpython

2008-12-30 Thread Joe Strout
Steve Holden wrote: I'd like the console to be a bidirectional representation of what's going on in the gui, plus a general purpose evaluation environment where you can manipulate application data via some api which is automatically exposed to the console when the application opens up. I'm look

Re: embedding python in wxpython

2008-12-30 Thread Steve Holden
5lvqbw...@sneakemail.com wrote: > Hi, I've looked around for a way to allow a python console from within > a wxPython application, but have only found stuff on embedded/ > extending python with C/C++ or wxWidgets in C++, but not wxPython. > > Is this easy to do? Can someone point me in the right

Re: embedding python in wxpython

2008-12-30 Thread Jervis Whitley
On Wed, Dec 31, 2008 at 7:21 AM, Stef Mientki wrote: > 5lvqbw...@sneakemail.com wrote: > >> Hi, I've looked around for a way to allow a python console from within >> a wxPython application, but have only found stuff on embedded/ >> extending python with C/C++ or wxWidgets in C++, but not wxPython.

Re: embedding python in wxpython

2008-12-30 Thread Stef Mientki
5lvqbw...@sneakemail.com wrote: Hi, I've looked around for a way to allow a python console from within a wxPython application, but have only found stuff on embedded/ extending python with C/C++ or wxWidgets in C++, but not wxPython. Is this easy to do? Can someone point me in the right directio

Re: embedding python in wxpython

2008-12-30 Thread Mike Driscoll
On Dec 30, 1:52 pm, 5lvqbw...@sneakemail.com wrote: > Hi, I've looked around for a way to allow a python console from within > a wxPython application, but have only found stuff on embedded/ > extending python with C/C++ or wxWidgets in C++, but not wxPython. > > Is this easy to do?  Can someone poi

Re: embedding python

2008-11-14 Thread Gabriel Genellina
En Thu, 13 Nov 2008 19:41:44 -0200, Alan Baljeu <[EMAIL PROTECTED]> escribió: Thanks, I have 2.5 now and it works great with Nose. Now for my next project, I want to embed Python and Nose in a C++ program. I know this means using the python25.dll, and I know how to setup the calls. I thin

Re: Embedding Python

2008-07-01 Thread Marcin Krol
Hello everyone, In the meantime I managed to work out another solution, mainly thanks to reading the source code of some OSS projects. I post it here so somebody else looking for solution to this problem had the example available: cut #include #include #include #include #include

Re: Embedding Python

2008-07-01 Thread Marcin Krol
Carsten Haese wrote: python_code is a C string containing the raw bytes from your pyc file. Casting that to a PyObject pointer will not magically transform it into a Python code object. well yeah, I kind of didn't think that through.. A pyc file contains the following: 1) An 8 byte head

Re: Embedding Python

2008-07-01 Thread Marcin Krol
Pau Freixes wrote: If you search this function name into Google you will can found some examples, use for example PyMarshal_ReadObjectFromString or PyMarshal_ReadObjectFromFile Rest assured I looked at a lot of code, but none of it was reading in the .pyc file. I had no idea about the 8-byte h

Re: Embedding Python

2008-07-01 Thread Carsten Haese
Marcin Krol wrote: Hello everyone, I'm trying to embed Python interpreter in C code, but in a specific way: loading compiled bytecode into a memory location and executing it (don't ask why, complicated reasons). PyImport_ExecCodeModule seems like obvious candidate, docs say: "Given a module na

Re: Embedding Python

2008-07-01 Thread Pau Freixes
Hi If PyImport_ExecCodeModule have a two parameteres and second parameter is PyObject type why you are make a call with a unsigned char value ? If you search this function name into Google you will can found some examples, use for example PyMarshal_ReadObjectFromString or PyMarshal_ReadObjectFro

Re: Embedding Python question.

2008-05-20 Thread Gabriel Genellina
En Tue, 20 May 2008 06:35:23 -0300, Thomas Troeger <[EMAIL PROTECTED]> escribió: I've successfully embedded the Python interpreter into a set of C/C++ application programs that use a larger library project with information from http://docs.python.org/api/api.html and http://docs.python.or

Re: Embedding Python - Freeing Python Objects Not Using Py_DECREF

2008-01-17 Thread Thomas Heller
[EMAIL PROTECTED] schrieb: > Hello, > > I'm embedding Python interpreter in a Win32 console application. I use > C++. > > I would like to use the WinAPI LoadLibrary function to load the python > dll at runtime (followed by GetProcAddress calls), so that I have to > make no assumptions about the l

Re: Embedding python code into text document question.

2008-01-11 Thread Thomas Troeger
Thanks guys, you've helped me very much :) Cheers & happy new year! -- http://mail.python.org/mailman/listinfo/python-list

Re: Embedding python code into text document question.

2008-01-10 Thread Erik Max Francis
Thomas Troeger wrote: > I've written a program that parses a string or file for embedded python > commands, executes them and fills in the returned value. The input might > look like this: > > process id: $$return os.getpid()$$ > current date: $$return time.ctime()$$ > superuser: $$ > if os.get

Re: Embedding python code into text document question.

2008-01-10 Thread MRAB
On Jan 10, 1:10 pm, Thomas Troeger <[EMAIL PROTECTED]> wrote: > Dear all, > > I've written a program that parses a string or file for embedded python > commands, executes them and fills in the returned value. The input might > look like this: > > process id: $$return os.getpid()$$ > current date: $

Re: Embedding python code into text document question.

2008-01-10 Thread Marc 'BlackJack' Rintsch
On Thu, 10 Jan 2008 14:10:05 +0100, Thomas Troeger wrote: > I've written a program that parses a string or file for embedded python > commands, executes them and fills in the returned value. The input might > look like this: > > process id: $$return os.getpid()$$ > current date: $$return time.c

Re: Embedding python code into text document question.

2008-01-10 Thread tezlo
Thomas Troeger <[EMAIL PROTECTED]> wrote: > I've written a program that parses a string or file for embedded > python commands, executes them and fills in the returned value. > ... > I've tried several solutions using eval, execfile or compile, but > none of those would solve my problem. Does anyon

Re: Embedding python code into text document question.

2008-01-10 Thread Thomas Troeger
Ok I've written a small example program to clarify matters: [SNIP] #!/usr/bin/python import os, sys, time def template(src, dst, sep): """ Copy file from src to dst, executing embedded python code. """ try: #

Re: Embedding python code into text document question.

2008-01-10 Thread grflanagan
On Jan 10, 2:10 pm, Thomas Troeger <[EMAIL PROTECTED]> wrote: > Dear all, > > I've written a program that parses a string or file for embedded python > commands, executes them and fills in the returned value. The input might > look like this: > > process id: $$return os.getpid()$$ > current date: $

Re: Embedding Python - Passing by Reference

2007-11-29 Thread andy
Thanks for the replies - I see that I completely misunderstood "passing by reference" when discussing Python. It looks like wrapping the object up in a list will be the path I go down as it remains closer to the C API I am wrapping. Thanks again! Andy -- http://mail.python.org/mailman/listinfo/p

Re: Embedding Python - Passing by Reference

2007-11-29 Thread Neil Cerutti
On 2007-11-29, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I understand the parameters to Python functions are passed by > reference: > > def foo(a): > a = a + 1 > > Will change the value of a in the calling function. How do I > implement the equivalent in C when extending Python? You've got

Re: Embedding Python - Passing by Reference

2007-11-29 Thread Terry Reedy
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] |I understand the parameters to Python functions are passed by reference: Nope. Python's name-object model is so far different from the named memory block model of Fortran/C/etc that terms invented for the latter are misleading when

Re: Embedding Python - Passing by Reference

2007-11-29 Thread Jean-Paul Calderone
On Thu, 29 Nov 2007 14:39:52 -0800 (PST), [EMAIL PROTECTED] wrote: >I understand the parameters to Python functions are passed by >reference: > >def foo(a): > a = a + 1 > >Will change the value of a in the calling function. How do I implement >the equivalent in C when extending Python? You misund

Re: embedding python..

2007-10-09 Thread [EMAIL PROTECTED]
That sounds to easy I will give it a shot.. On Oct 6, 11:08 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Fri, 05 Oct 2007 20:40:40 -0300, [EMAIL PROTECTED] > <[EMAIL PROTECTED]> escribi?: > > > I compiled the c program that is supposed to allow you to call a > > procedure from th

Re: embedding python..

2007-10-06 Thread Gabriel Genellina
En Fri, 05 Oct 2007 20:40:40 -0300, [EMAIL PROTECTED] <[EMAIL PROTECTED]> escribi�: > I compiled the c program that is supposed to allow you to call a > procedure from the command line promt.. (it is from the embeding > example).. I am a little confused as to what all I am supposed to > d

Re: Embedding Python in C

2007-06-06 Thread mistabean
On 6 Jun., 05:44, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > Python lists and tuples are "generic" containers: both can contain any > kind of object, and each item may be of a different type: (1, 2.0, 3+0j, > "four", u"Fünf", file("six")) is a tuple containing 6 items, all of > differe

Re: Embedding Python in C

2007-06-05 Thread Gabriel Genellina
En Tue, 05 Jun 2007 03:41:19 -0300, <[EMAIL PROTECTED]> escribió: > On 5 Jun., 01:32, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: >> Yes, it appears that you are building a plain list but your code is >> expecting another kind of object. I'm unfamiliar with Numeric arrays, if >> that is what y

Re: Embedding Python in C

2007-06-05 Thread Joe Riopel
This seems like a pretty good resource, although I didn't read it all yet: http://www.ibm.com/developerworks/edu/l-dw-linux-pythonscript-i.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Embedding Python in C

2007-06-05 Thread mistabean
now then... where's the edit button...? oh well, double-posting. Problem solved, thanks for pointing out that I am needing a numeric array built instead of building a normal list/ tuple. For those who are curious, steps to solving: ... #include "libnumarray.h" /*from numpy*/ ... ... ... void Cal

Re: Embedding Python in C

2007-06-04 Thread mistabean
On 5 Jun., 01:32, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Mon, 04 Jun 2007 11:58:38 -0300, <[EMAIL PROTECTED]> escribió: > > > > > > > Onwards to the problem, I have been having difficulty embedding a > > python module into my C/C++ program. (just a test program before > > moving on int

Re: Embedding Python in C

2007-06-04 Thread Gabriel Genellina
En Mon, 04 Jun 2007 11:58:38 -0300, <[EMAIL PROTECTED]> escribió: > Onwards to the problem, I have been having difficulty embedding a > python module into my C/C++ program. (just a test program before > moving on into the real thing). I have been making test runs using the > codes from http://docs

Re: embedding python -- windows specify problems

2006-10-05 Thread John Pye
Hi Fredrik, Thanks very much for that reply. Your suggestion sounds feasible, I guess. Taking what you said, and thinking about how I could avoid adding an additional intepreter step, I thought that I could try the following: pyfile = PyFile_FromString(name,"r"); if(pyfile==NULL){

Re: embedding python -- windows specify problems

2006-10-05 Thread Fredrik Lundh
> the contents and the layout of the FILE structure isn't defined "isn't standardized", that is. -- http://mail.python.org/mailman/listinfo/python-list

Re: embedding python -- windows specify problems

2006-10-05 Thread Fredrik Lundh
John Pye wrote: > I have been working on some new code that embeds python in an C > application. The embedding is working fine under Linux but crashing > under Windows (XP) when I reach the following step. > > PyRun_AnyFile(f,name); > > If there's some python exception being thrown by the PyRun_An

Re: Embedding Python and command history

2006-09-20 Thread Stefan Bellon
Stefan Bellon wrote: > int main(void) > { > Py_Initialize(); > PyRun_InteractiveLoop(stdin, ""); > Py_Finalize(); > } > How can I make use of command history when embedded Python via > PyRun_InteractiveLoop? Sorry to follow up my own posting ... I found that when I do "import readline" in

Re: Embedding python: GCC gives errors of "undefined reference" to Py_* functions.

2006-08-19 Thread Shuaib
OK, I am not ashamed to admit that I am ashamed as I didn't search the group for my problem before posting it yet again. The solution was right there. I have link in my libpython2.4.so while compiling. $gcc -I/usr/include/python2.4/ -lpython2.4 -o foo foo.c Shuaib wrote: > Hey! > > I am trying

Re: Embedding Python in C/C++

2006-08-10 Thread kingcrustybun
We are still struggling with this but having spent many hours looking at related code on the net, i have noticed the following sequence quite a lot globals = PyDict_New(); PyDict_SetItemString(globals, "__builtins__", PyEval_GetBuiltins()); Can anyone explain what this does exactly? I know what "

RE: embedding Python in COM server loaded with win32com

2006-06-06 Thread Stefan Schukat
Hi, when you are running in Python the PyInitialize() is not called and therefore you don't have a valid threadstate since the call in win32com uses the standard idiom Py_BEGIN_ALLOW_THREADS() CallComServer Py_END_ALLOW_THREADS() You could use PyNewInterpreter to get a valid state, but this w

Re: Embedding Python

2006-05-09 Thread Serge Orlov
gavinpaterson wrote: > Dear Pythoners, > > I am writing as I am having trouble embedding a Python program into a > Win XP C++ console application. > > I have written a script file for importing and I am trying to use the > example for "Pure Embedding" found in the product documentation. > > The pro

Re: Embedding Python: How to run compiled(*.pyc/*.pyo) files using Python C API?

2006-05-05 Thread Serge Orlov
Shankar wrote: > Hello, > > I am trying to run compiled Python files (*.pyc and *.pyo) using Python C > API. > > I am using the method PyRun_FileFlags() for this purpose. > > The code snippet is as follows:- > > PyCompilerFlags myFlags; > myFlags.cf_flags=1; // I tried all values 0, 1 and 2 > PyRun

Re: embedding Python: how to avoid memory leaks?

2006-03-10 Thread Wolfgang
Hallo, > >>> I couldn't get the PyRun_*File* calls to work on Windows, > >>> presumably because of the FILE* problem mentioned in the docs. > >> > >> Which compiler do you use? > > > > MSVC++ (version 6 from memory -- I do most of my development on > > the Mac and fire up Virtual PC occasionally t

Re: embedding Python: how to avoid memory leaks?

2006-03-10 Thread Martin v. Löwis
Torsten Bronger wrote: I couldn't get the PyRun_*File* calls to work on Windows, presumably because of the FILE* problem mentioned in the docs. > Well, I don't really *know*, but it's hard to believe to me that the > file descriptor format changed within the Microsoft product series. The

  1   2   >