ctypes - python2.7.3 vs python3.2.3

2012-08-28 Thread Rolf
ctypes works as I would expect with python2.7.3.

However, when I upgrade to python3.2.3 things don't seem to work right. Look 
below for details.

I am not sure where I am going wrong.

Shared Library
==
#include 
#include 

extern "C"
{
   int main();
   uint32_t myfunction (char **);
}

uint32_t myfunction (char ** _mydata)
{
   char mydata[16];

   strcpy(mydata, "Hello Dude!");

   *_mydata = mydata;

   return 0;
}

int main()
{
   return 0;
}

Python 2.7.3 which works as I would expect
==
> python2.7 -V
Python 2.7.3

> cat py27.py
#!/usr/bin/env python2.7

from __future__ import print_function
from __future__ import unicode_literals

from ctypes import *

lib = CDLL('libtest.so')
o_result = c_char_p()
lib.myfunction(pointer(o_result))
print(repr(o_result.value))

> ./py27.py
'Hello Dude!'

Python 3.2.3 return string gets mangled
===
> python3 -V
Python 3.2.3

> cat py3.py
#!/usr/bin/env python3

from ctypes import *

lib = CDLL('libtest.so')
o_result = c_char_p()
lib.myfunction(pointer(o_result))
print(repr(o_result.value))

> ./py3.py
b'\xd8\xb0y\to Dude!'

Every time I run it, I get a different set of values.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to install setuptools...egg?

2009-08-30 Thread Rolf

Hi,

I would like to install setuptools for Python2.6 on Windows. 
Unfortunately I could only find setuptools-0.6c9-py2.6.egg but no *.exe 
for Python2.6. And as far as I understand I need setuptools to install a 
Python egg. I would be very appreciative for any help.


Regards

Rolf
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to install setuptools...egg?

2009-08-30 Thread Rolf

Mike schrieb:

I would like to install setuptools for Python2.6 on Windows.


1. Download setuptools-0.6c9-py2.6.egg
2. Download setuptools-0.6c9.tar.gz
3. Use 7-zip from  http://www.7-zip.org/ to extract ez_setup.py from
setuptools-0.6c9.tar.gz
4. In a directory that contains setuptools-0.6c9-py2.6.egg and
ez_setup.py run the command python ez_setup.py
5. Add C:\Python26\Scripts to your path to run easy_install

Mike

Thank you very much. Your recipe did the job.

Rolf
--
http://mail.python.org/mailman/listinfo/python-list


Compile python code into a dll

2012-09-10 Thread Rolf Wester

Hi,

I have Python code that I would like to compile into a dll (I have to 
deliver a C/C++ callable dll and I don't want to reimpelement the Python 
code in C/C++). It's not for extending Python but I want to call the 
Python functions and classes from C/C++. It's more like extending C/C++ 
with Python. I would be very appreciative for any help.


Thank you in advance

Regards
Rolf
--
http://mail.python.org/mailman/listinfo/python-list


Re: Compile python code into a dll

2012-09-11 Thread Rolf Wester

Thank you all for your help. I'm going to try Cython.

Regards
Rolf


On 10/09/12 14:15, Rolf Wester wrote:

Hi,

I have Python code that I would like to compile into a dll (I have to
deliver a C/C++ callable dll and I don't want to reimpelement the Python
code in C/C++). It's not for extending Python but I want to call the
Python functions and classes from C/C++. It's more like extending C/C++
with Python. I would be very appreciative for any help.

Thank you in advance

Regards
Rolf


--
http://mail.python.org/mailman/listinfo/python-list


exec

2012-03-01 Thread Rolf Wester
Hi,

I would like to define methods using exec like this:

class A:
def __init__(self):
cmd = "def sqr(self, x):\nreturn x**2\nself.sqr = sqr\n"
exec cmd
a = A()
print a.sqr(a, 2)

This works, but I have to call sqr with a.sqr(a, 2), a.sqr(2) does not work
(TypeError: sqr() takes exactly 2 arguments (1 given)).

Is there a possibility to define methods using exec and getting normal behavior?

I would be very appreciative for any help.

With kind regards
Rolf Wester


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: exec

2012-03-01 Thread Rolf Wester
Hi,

thanks for your replies so far.

The reason to use exec is just laziness. I have quite a lot of classes
representing material data and every class has a number of parameters.
The parameter are Magnitude objects (they have a value and a unit and overloaded
special functions to correctly handle the units). I want to have getter
functions that either return the Magnitude object or just the value:

iron = Iron()
iron.rho(0) => value
iron.rho() => Magnitude object

def rho(self, uf=1):
if uf == 1:
return self._rho
else:
return self._rho.val

And because this would mean quite a lot of writing I tried to do it with exec.

With kind regards
Rolf Wester
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: exec

2012-03-01 Thread Rolf Wester
Thank you, that really made things much easier and admittedly much less nasty 
too.

Regards
Rolf

On 01/03/12 18:14, Peter Otten wrote:
> Rolf Wester wrote:
> 
>> The reason to use exec is just laziness. I have quite a lot of classes
>> representing material data and every class has a number of parameters.
>> The parameter are Magnitude objects (they have a value and a unit and
>> overloaded special functions to correctly handle the units). I want to
>> have getter functions that either return the Magnitude object or just the
>> value:
>>
>> iron = Iron()
>> iron.rho(0) => value
>> iron.rho() => Magnitude object
>>
>> def rho(self, uf=1):
>> if uf == 1:
>> return self._rho
>> else:
>> return self._rho.val
>>
>> And because this would mean quite a lot of writing I tried to do it with
>> exec.
> 
> Make the Magnitude class callable then:
> 
>>>> class Magnitude(object):
> ... def __init__(self, value):
> ... self.value = value
> ... def __call__(self, uf=1):
> ... if uf == 1:
> ... return self
> ... return self.value
> ...
>>>> class Iron(object):
> ... def __init__(self):
> ... self.rho = Magnitude(42)
> ...
>>>> iron = Iron()
>>>> iron.rho()
> <__main__.Magnitude object at 0x7fb94062be10>
>>>> iron.rho(0)
> 42
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


starting Python 3.10.4 64-bit

2022-05-27 Thread Rolf Blum

Hallo,
I installed Python 3.10.4 64-bit successfully. I Also checked in the 
Setup to add it to the path.

In the win 8.1 console python 3.7 is started when I enter: python.
This also happened after a reboot and after a repair with the Setup.
How do I start the python console for 3.10.4?
Thanks
--
https://mail.python.org/mailman/listinfo/python-list


Re: Windows Gui Frontend

2023-04-03 Thread Rolf Blum

Am 02.04.2023 um 01:13 schrieb Alan Gauld:

On 01/04/2023 18:21, Jim Schwartz wrote:

Are there any ide’s that will let me design the screen and convert it to python?


There is nothing remotely like the VB or Delphi GUI builders.


The latest Delphi versions themself can create GUIs for Python. I use 
Delphi 10.4.2 (Sidney) Professional.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Promoting Python

2016-04-06 Thread Rolf Camps



Op 07-04-16 om 00:03 schreef Marko Rauhamaa:

Once you look up an object method, it doesn't have a self argument. The
self argument is cooked up for the benefit of the function definition in
the class.

IOW, if I have this class:

 class A:
 def f(self):
 print("f")

and this object:

 a = A()

then,

 a.f

is a function that doesn't have a self argument. That function is
generated on the fly, and it delegates to A.f, providing it with self
argument.

a.f is not a function, A.f is a function.
a.f is an instance method. The function is not generated on the fly, 
when the method is called, it calls the function A.f with an extra 
argument __self__ (the instance a) inserted before the argument list the 
instance method was called with.

So calling a.f() is a convenient way to write A.f(a)


However, a.f itself is just a function that doesn't accept any
arguments.
As i wrote, a.f is an instance method not a function. It accepts any 
argument you trow at it, insert 'a' in front of the argument list and 
calls the function A.f with this new argument list.


Defining:

 def f():
 print("f")
 a.f = f

simply short-circuits the attribute lookup process; no need to consult
the class when the attribute (method!) is right there in the object's
dict.
Here a.f is a function so Python will treat is as a function. When you 
call it, the lookup process will find f in the class instance 
dictionary, discover it's a function and run it with the arguments 
provided. If you would like to use  attributes of the class A or of the 
instance 'a' in f, you would need to hard code it in the function since 
the function f does not know it was called from 'a', an instance of the 
class A.



Marko

--
https://mail.python.org/mailman/listinfo/python-list


Re: deque is not a subclass of Sequence.

2016-04-07 Thread Rolf Camps



On 2016-04-07 11:12, Peter Otten wrote:

Antoon Pardon wrote:


Second tryal, I hope the formatting doesn't get messed up now

Playing around with the collections and collections.abc modules in
python3.4 I stumbled upon the following:


from collections.abc import Sequence
from collections import deque
isinstance(list(), Sequence)

True

isinstance(deque(), Sequence)

False

This seems strange to me. As far as I understand, the
documentation indicates there is no reason why deque
shouldn't be a subclass of Sequence.

Am I missing something or can this be considered a bug?

from collections import deque
from collections.abc import Sequence
[name for name in set(dir(Sequence)) - set(dir(deque)) if not

name.startswith("_")]
['index']

So the index() method seems to be what is missing.


The index method was added to the deque object in Python 3.5.

Python 3.5.1 (default, ...)
[GCC ...] on linux
>>> import collections
>>> isinstance(collections.deque(), collections.abc.Sequence)
True

--
https://mail.python.org/mailman/listinfo/python-list


Python extension module segmentation fault

2005-10-21 Thread Rolf Wester
Hi,

I' trying to make an extension module that passes Numeric arrays. The
wrapper function is (swig generated and modified by myself):

static PyObject *_wrap_my_func(PyObject *self, PyObject *args) {
PyObject * resultobj = 0 ;
PyObject * obj0 = 0 ;
PyArrayObject * mat = 0 ;

std::cout << __FILE__ << "  " <<  __LINE__ << std::endl;
if(!PyArg_ParseTuple(args,(char *)"O:my_func",&obj0)) goto fail;
std::cout << __FILE__ << "  " <<  __LINE__ <<  "  " << obj0 << 
std::endl;
mat = (PyArrayObject *) PyArray_ContiguousFromObject(obj0,
PyArray_DOUBLE, 1, 1);
std::cout << __FILE__ << "  " <<  __LINE__ <<  "  " << mat << std::endl;

Py_INCREF(Py_None); resultobj = Py_None;
return resultobj;
fail:
return NULL;
}

The shared object is build with:

g++ -c -g -fPIC -I./  -I/usr/local/include/python2.4
-I/usr/local/include/python2.4/Numeric  mytest_wrap.cpp -o mytest_wrap.o

g++ -shared -L/usr/local/lib/python2.4/config/  mytest_wrap.o
-lpython2.4 -lm   -o _mytest.so


the Python file reads:

import _mytest
from Numeric import *
mat = ones(100,Float64)
print _mytest.my_func(mat)

When running this I get the output:

mytest_wrap.cpp  1499
mytest_wrap.cpp  1502  0x402b55e8
Speicherzugriffsfehler (segmentation fault)

I also ran this with valgrind. Part of valgrinds output is:

==15792== Reading syms from
/mnt/pubdsk/A31/2003/DOKUMENTATION/WESTER/pr3/OPT/opt2.0/test/_mytest.so
(0x1BE7E000)
==15792== Reading syms from
/usr/local/lib/python2.4/site-packages/Numeric/multiarray.so (0x1B90F000)
==15792== Reading syms from
/usr/local/lib/python2.4/site-packages/Numeric/_numpy.so (0x1BFDB000)
==15792== Reading syms from
/usr/local/lib/python2.4/site-packages/Numeric/umath.so (0x1BFF1000)
==15792== Reading syms from
/usr/local/lib/python2.4/lib-dynload/strop.so (0x1B91A000)
==15792== Reading syms from /usr/local/lib/python2.4/lib-dynload/math.so
(0x1C103000)
==15792== Reading syms from
/usr/local/lib/python2.4/lib-dynload/struct.so (0x1C209000)
==15792== Reading syms from
/usr/local/lib/python2.4/lib-dynload/binascii.so (0x1C21)
==15792== Reading syms from
/usr/local/lib/python2.4/lib-dynload/cStringIO.so (0x1C216000)
mytest_wrap.cpp  1499
mytest_wrap.cpp  1502  0x1bca7610
==15792== Invalid read of size 4
==15792==at 0x1BECE794: _wrap_my_func (mytest_wrap.cpp:1503)
==15792==by 0x811E685: PyCFunction_Call (methodobject.c:93)
==15792==by 0x80C708F: PyEval_EvalFrame (ceval.c:1499)
==15792==by 0x80C8933: PyEval_EvalCodeEx (ceval.c:2736)
==15792==by 0x80C8B64: PyEval_EvalCode (ceval.c:484)
==15792==by 0x80F74A7: PyRun_SimpleFileExFlags (pythonrun.c:1265)
==15792==by 0x80558D6: Py_Main (main.c:484)
==15792==by 0x8054F86: main (python.c:23)
==15792==  Address 0x38 is not stack'd, malloc'd or (recently) free'd
==15792==
==15792== Process terminating with default action of signal 11 (SIGSEGV)
==15792==  Access not within mapped region at address 0x38
==15792==at 0x1BECE794: _wrap_my_func (mytest_wrap.cpp:1503)
==15792==by 0x811E685: PyCFunction_Call (methodobject.c:93)
==15792==by 0x80C708F: PyEval_EvalFrame (ceval.c:1499)
==15792==by 0x80C8933: PyEval_EvalCodeEx (ceval.c:2736)
==15792==by 0x80C8B64: PyEval_EvalCode (ceval.c:484)
==15792==by 0x80F74A7: PyRun_SimpleFileExFlags (pythonrun.c:1265)
==15792==by 0x80558D6: Py_Main (main.c:484)
==15792==by 0x8054F86: main (python.c:23)
==15792==
==15792== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 8093 from 7)
==15792==


I would be very appreciative for any help.

With kind regards

Rolf Wester




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python extension module segmentation fault

2005-10-21 Thread Rolf Wester
Robert Kern wrote:

> 
> 
> Did you call import_array() in init_mytest()?
> 
No I didn't. Thank you very much for your help. Now it works.

With kind regards

Rolf Wester
-- 
http://mail.python.org/mailman/listinfo/python-list


run region in IDLE

2005-01-02 Thread Rolf Wester
Hi,
I would like to send a marked region of an IDLE editing window to the 
IDLE shell for evaluating, so that I can develop software incrementally.
I know that I could type directly into the shell window (or copy and 
paste between an editing window and the shellwindow) but I'm looking for 
a way of doing it like it's possible with Emacs and Python. Is there any 
way of doing this?

Regards
Rolf Wester
--
http://mail.python.org/mailman/listinfo/python-list


Embedding a restricted python interpreter

2005-01-04 Thread Rolf Magnus
Hi,

I would like to embed a python interpreter within a program, but since that
program would be able to automatically download scripts from the internet,
I'd like to run those in a restricted environment, which basically means
that I want to allow only a specific set of modules to be used by the
scripts, so that it wouldn't be possible for them to remove files from the
hard drive, kill processes or do other nasty stuff.
Is there any way to do that with the standard python interpreter?

-- 
http://mail.python.org/mailman/listinfo/python-list


IDLE question

2004-12-26 Thread Rolf Wester
Hi,
I would like to use IDLE as interactively as I can with Emacs. In Emacs 
I can send a marked region to the Python interpreter. Is there any way 
to do the same thing with IDLE?

Thank you in advance
Regards
Rolf Wester
--
http://mail.python.org/mailman/listinfo/python-list


Re: simultaneous copy to multiple media

2005-03-20 Thread Rolf Zwart
Swaroop C H wrote:
[...]
If you are using *nix, maybe you can use the `tee` command[1] and
redirect the file to different places.
For example,
cat  | tee file1 | tee file2 > file3
On Unixes I know, only 1 process is needed:
/dev/null
It does work!
** Rolf
I haven't tried it out but it should work.
[1]: http://unixhelp.ed.ac.uk/CGI/man-cgi?tee
HTH,
--
http://mail.python.org/mailman/listinfo/python-list


Re: what does 'a=b=c=[]' do

2011-12-22 Thread Rolf Camps
alex23 schreef op wo 21-12-2011 om 16:50 [-0800]:
> On Dec 22, 8:25 am, Eric  wrote:
> > This surprises me, can someone tell me why it shouldn't?  I figure if
> > I want to create and initialize three scalars the just do "a=b=c=7",
> > for example, so why not extend it to arrays.
> 
> The thing to remember is that everything is an object, and that it's
> better to think of variables as labels on an object.
> 
> So: a=b=c=7 means that _one_ integer object with the value of 7 can be
> referenced using any of the labels a, b or c. x=y=z=[] means that
> _one_ empty list can be referenced using x, y or z.
> 
> The difference is that the value of a number object _cannot be
> changed_ ('immutable') while a list can be modified to add or remove
> items ('mutable'). a=10 just reassigns the label a to an integer
> object of value 10. x.append("foo") _modifies_ the list referred to by
> x, which is the same list known as y & z.
> 
> > Also, is there a more pythonic way to do "x=[], y=[], z=[]"?
> 
> I'd say that _is_ the most pythonic way, it's very obvious in its
> intent (or would be with appropriate names). If it bothers you that
> much:
> 
> def listgen(count, default=[]):
> for _ in xrange(count):
> yield default[:]
> 
> x, y, z = listgen(3)
> 


I'm afraid it's dangerous to encourage the use of '[]' as assignment to
a parameter in a function definition. If you use the function several
times 'default' always points to the same list. 

>>> def return_list(list_ = []):
>>> return list_
>>> a_list = return_list()
>>> a_list
[]
>>> a_list.append(3)
>>> a_list
[3]
>>> b_list = return_list()
>>> b_list
>>> [3]   # !!??

>>> def return_list():
>>> return []
>>> a_list = return_list()
>>> a_list
[]
>>> a_list.append(3)
>>> a_list
[3]
>>> b_list = return_list()
>>> b_list
>>> []# OK!

I only use python3 so I don't know how these things work in other
versions.

No problem in your function since you yield a copy, but I've already
seen long threads about this.

I would change your function to (Python3.x):

def empty_lists(count):
for _ in range(count):
yield []


Regards,

Rolf




-- 
http://mail.python.org/mailman/listinfo/python-list


Strange behaviour of Numeric Float32 array?

2006-07-12 Thread Rolf Wester
Hi,

the code:

from Numeric import *

def my_minimum(a):
n=shape(a)[0]
x = 1.0e20
for i in range(n):
if a[i] < x:
x = a[i]
return x



def strange(a):
a[3] = -6303.0
h = my_minimum(a)
for i in range(10):
print i,a[i],
a[i] = a[i] - h
print a[i],h

a = zeros(10,Float32)
strange(a)
b = zeros(10,Float64)
strange(b)

produces the output:

0 0.0 6303.0 -6303.0
1 0.0 6303.0 -6303.0
2 0.0 6303.0 -6303.0
3 -6303.0 0.0 0.0
4 0.0 0.0 0.0
5 0.0 0.0 0.0
6 0.0 0.0 0.0
7 0.0 0.0 0.0
8 0.0 0.0 0.0
9 0.0 0.0 0.0
0 0.0 6303.0 -6303.0
1 0.0 6303.0 -6303.0
2 0.0 6303.0 -6303.0
3 -6303.0 0.0 -6303.0
4 0.0 6303.0 -6303.0
5 0.0 6303.0 -6303.0
6 0.0 6303.0 -6303.0
7 0.0 6303.0 -6303.0
8 0.0 6303.0 -6303.0
9 0.0 6303.0 -6303.0

Can anybody tell me why in the Float32 version h is changed?
Thank you in advance.

Regards

Rolf
-- 
http://mail.python.org/mailman/listinfo/python-list


concatenating numpy arrays

2006-10-31 Thread Rolf Wester
Hi,

I want to concatenate two numpy arrays with shape (n1,n2) and (n1,n3) 
into a single array with shape (n1,n2+n3). I guess there is an elegant 
way to do this but I couldn't figure it out. So any help is very much 
appreciated.

Regards

Rolf
-- 
http://mail.python.org/mailman/listinfo/python-list


Is there a Python __LINE__ ?

2006-07-06 Thread Rolf Wester
Hi,

is there a Python aquivalent to the C __LINE__?

Thank you in advance

Regards

Rolf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a Python __LINE__ ?

2006-07-06 Thread Rolf Wester
Thank you very much for your help.

Regards

Rolf
-- 
http://mail.python.org/mailman/listinfo/python-list


plotting with Python

2005-05-30 Thread Rolf Wester
Hi,

I have a Python console application that is intended to be used 
interactively and I have to add plotting capabilities (multiple XY plots 
and if possible 2D-surface plots). I'm loocking for a reasonably fast 
plotting library (not GPL'ed, needs not be for free) that can be used 
under Windows. An alternative would also be a standalone application 
that can be controlled via TCP/IP from my Python application. I tried 
matplotlib but this is not fast enough (especially under Windows). I 
considered PyQwt but this is GPL'ed. So I would be very appreciative for 
any help.

With kind regards

Rolf Wester
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: plotting with Python

2005-05-31 Thread Rolf Wester
Philippe C. Martin wrote:
> Look at wxPython
> 
> Regards,
> 
> Philippe
> 
> 
I will do it, thank you for your reply.

Rolf

> 
> Rolf Wester wrote:
> 
> 
>>Hi,
>>
>>I have a Python console application that is intended to be used
>>interactively and I have to add plotting capabilities (multiple XY plots
>>and if possible 2D-surface plots). I'm loocking for a reasonably fast
>>plotting library (not GPL'ed, needs not be for free) that can be used
>>under Windows. An alternative would also be a standalone application
>>that can be controlled via TCP/IP from my Python application. I tried
>>matplotlib but this is not fast enough (especially under Windows). I
>>considered PyQwt but this is GPL'ed. So I would be very appreciative for
>>any help.
>>
>>With kind regards
>>
>>Rolf Wester
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: plotting with Python

2005-05-31 Thread Rolf Wester
[EMAIL PROTECTED] wrote:
> We use dislin in my lab. I don't think it's GPL...
> 
> http://www.linmpi.mpg.de/dislin
> 
Hi,

thank you for your reply. I tried dislin but this didn't work very well 
for me. But I will try it again.

Regards


Rolf

-- 
http://mail.python.org/mailman/listinfo/python-list


Memory problem

2007-11-15 Thread Rolf Wester
Hi,

I have a strange (for me) memory problem. When running a loop in a 
Python program memory usage increases from about 4% up to 100%. I do a 
gc.collect() every loop cycle but this doesn't help. There are about 
67000 objects that are tracked by the garbage collector. This number 
does vary a little bit but does not increase on average whereas the 
memory usage does. The number of garbage objects (len(gc.garbage()) is 
zero. This is a very severe problem for my application, so I would be 
very appreciative for any help.

With kind regards

Rolf

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Memory problem

2007-11-15 Thread Rolf Wester
Sorry, of course your are wright. I'm running Python2.5 on Linux, my 
program imports numpy, matplotlib, sys and a python module of my own.
This module uses numpy and scipy.weave for imbedded C-code but no 
extension modules. I though the code to be to large to show, I hoped you 
could give me hint on what I could try.

Thank you in advance

Rolf

Diez B. Roggisch wrote:
> Rolf Wester wrote:
> 
>> Hi,
>>
>> I have a strange (for me) memory problem. When running a loop in a
>> Python program memory usage increases from about 4% up to 100%. I do a
>> gc.collect() every loop cycle but this doesn't help. There are about
>> 67000 objects that are tracked by the garbage collector. This number
>> does vary a little bit but does not increase on average whereas the
>> memory usage does. The number of garbage objects (len(gc.garbage()) is
>> zero. This is a very severe problem for my application, so I would be
>> very appreciative for any help.
> 
> well, it might be that the relative moon humidity resonates with the
> loop-cycle, creating quantum-flux in the main memory banks.
> 
> Or not.
> 
> Seriously - what help do you expect without showing us _any_ code or at
> least getting into details like usage of libs, python-version, possible
> C-extensions, platform, 
> 
> Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Memory problem

2007-11-16 Thread Rolf Wester
Hi,

thank you for your comments and your hints (I probably deserve some kind 
of subtle irony). I found the problem:

I thought a numpy array A has shape (n,) but actually it had shape 
(n,1). In the loop I sampled a value from that array:

v.append(A[i])

So what happened was that I got a view of A not a single number and 
append obviously appended the whole array not just a single element 
array. And n is about 64000.

So sorry for bothering you with that stupid fault.

Regards

Rolf
-- 
http://mail.python.org/mailman/listinfo/python-list


Tool for translating Matlab to Python?

2007-12-04 Thread Rolf Wester
Hi,

is there a tool to automatically translate Matlab source to Python/numpy 
code?

Regards

Rolf
-- 
http://mail.python.org/mailman/listinfo/python-list


Strange constructor behaviour (or not?)

2006-04-28 Thread Rolf Wester
Hi,

when defining:

class A:
def __init__(self, l=[]):
self.l = l
a = A()
a.l.append()
b = A()
print a.l

I get the output

[]

instead of an empty list. I guess it's because the default value in the 
constructor is constructed once and whenever the constructor is called 
without l being specified.

My work around is:

class A:
def __init__(self, l=None):
if l == None:
self.l = []
else:
self.l = l

Is there a way to take the first definition but force the constructor to 
create a new empty list every time it is called?

Thanks in advance

Rolf Wester
-- 
http://mail.python.org/mailman/listinfo/python-list


plotting in python 3

2010-04-06 Thread Rolf Camps
Hi,

What's the easiest way to plot graphs in python 3.x? Ís there a package?
Quality doesn't really matter.

Thanks,

Rolf


signature.asc
Description: Dit berichtdeel is digitaal ondertekend
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: plotting in python 3

2010-04-06 Thread Rolf Camps
Op dinsdag 06-04-2010 om 14:55 uur [tijdzone -0500], schreef Christopher
Choi:
> On Tue, 06 Apr 2010 21:23:34 +0200, Rolf Camps wrote:
> 
> > Hi,
> > 
> > What's the easiest way to plot graphs in python 3.x? Ís there a package?
> > Quality doesn't really matter.
> > 
> > Thanks,
> > 
> > Rolf
> > Hi,
> > 
> > What's the easiest way to plot graphs in python 3.x? Ís there a package?
> > Quality doesn't really matter.
> > 
> > Thanks,
> > 
> > Rolf
> 
> I would like to think you have done some home work yourself 
> but anyways... gnuplot with python seems easy.

> .
> 
> http://gnuplot-py.sourceforge.net/doc/


It was after the homework I asked my question. All plot solutions i
found where for python2.x. gnuplot_py states on its homepage you need a
'working copy of numpy'. I don't think numpy is ported to python 3.x. Or
is it? 
> 
> Chris



signature.asc
Description: Dit berichtdeel is digitaal ondertekend
-- 
http://mail.python.org/mailman/listinfo/python-list


C-extension 2 times slower than exe

2009-06-23 Thread Rolf Wester
Hi,

I have a C++ program that I would like to steer using Python. I made the
wrapper using swig and linked the code (without the main function) into
a shared object. My Python script loads the extension and calls a
function of the C-extension, the rest runs entirely within the
C-extension. For comparison I compiled the code including the main
function with the same compilation options and linked all into an exe.
The main function of the exe calls the same function as my Python script
does. Surprisingly the code in the Python C-extension runs twice as long
as the same code in the exe. Does anyone know what could be the reason
for this behaviour?

Thank you in advance

Rolf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C-extension 2 times slower than exe

2009-06-23 Thread Rolf Wester
Philip Semanchuk wrote:
> 
> On Jun 23, 2009, at 9:51 AM, Rolf Wester wrote:
> 
>> Hi,
>>
>> I have a C++ program that I would like to steer using Python. I made the
>> wrapper using swig and linked the code (without the main function) into
>> a shared object. My Python script loads the extension and calls a
>> function of the C-extension, the rest runs entirely within the
>> C-extension. For comparison I compiled the code including the main
>> function with the same compilation options and linked all into an exe.
>> The main function of the exe calls the same function as my Python script
>> does. Surprisingly the code in the Python C-extension runs twice as long
>> as the same code in the exe. Does anyone know what could be the reason
>> for this behaviour?
> 
> If the runtime of the C/C++ code is short, the time spent initializing
> the Python interpreter might have a big impact on the runtime of the
> Python version.
> 
> 
The runtime is about 2.5 sec and 5.0 sec respectively. I not only use
the time command to measure the time consumed but I also measure the
time within the C-code using clock() and get similar result. So the
Python startup time is not the reason for the runtime difference I
found. Thank you anyway.

Rolf
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C-extension 2 times slower than exe

2009-06-24 Thread Rolf Wester
Hello,

thank you all very much for your replies.

I tried to simplify things and make the two versions as comparable as
possible. I put the C++ part of the program into a shared object
libff.so. For the exe the main function is linked against this shared
object. For the python stuff I made an interface consiting of only one
function call_solver with the same code that has the main function used
for the exe. Then I created a wrapper for this interface using swig and
linked interface.o, ff_warp.o and libff.so into _ff.so. The Python code
just imports _ff and calls call_solver wich creates an object of the
class Solver and calls its member solve (the main function of the exe
does the same).

I included some code for timing into the C++-code.

#include 

//beginning of solve
clock_t t0 = clock();
...
clock_t t1 = clock();
//end of solve
cout << "time used = " << (t1-t0)/CLOCKS_PER_SEC << endl;

I'm using gcc4.5 (latest snapshot) and Python2.6 under Suse 10.3. The
sources are compiled using the flags -fPIC -O3.

Timing:

1) time python ff.py
time used = 3.74
real0m3.234s
user0m3.712s
sys 0m0.192s
2) time ff
time used = 2.19
real0m3.170s
user0m2.088s
sys 0m0.168s

I tried some other optimizations:

-O0:

1)
time used = 21.91
real0m21.568s
user0m22.001s
sys 0m0.160s

2)
time used = 20.87
real0m22.206s
user0m20.989s
sys 0m0.148s

-O1
1)
time used = 4.04
real0m3.660s
user0m4.000s
sys 0m0.160s

2)
time used = 2.72
real0m3.454s
user0m2.648s
sys 0m0.164s

It seems that there is an overhead of about 2 secs within the C++-code.
I'm going to try this out with a problem that takes much more time than
the present one.

Regards

Rolf

Carl Banks wrote:
> On Jun 23, 7:20 am, Rolf Wester  wrote:
>> Philip Semanchuk wrote:
>>
>>> On Jun 23, 2009, at 9:51 AM, Rolf Wester wrote:
>>>> Hi,
>>>> I have a C++ program that I would like to steer using Python. I made the
>>>> wrapper using swig and linked the code (without the main function) into
>>>> a shared object. My Python script loads the extension and calls a
>>>> function of the C-extension, the rest runs entirely within the
>>>> C-extension. For comparison I compiled the code including the main
>>>> function with the same compilation options and linked all into an exe.
>>>> The main function of the exe calls the same function as my Python script
>>>> does. Surprisingly the code in the Python C-extension runs twice as long
>>>> as the same code in the exe. Does anyone know what could be the reason
>>>> for this behaviour?
>>> If the runtime of the C/C++ code is short, the time spent initializing
>>> the Python interpreter might have a big impact on the runtime of the
>>> Python version.
>> The runtime is about 2.5 sec and 5.0 sec respectively. I not only use
>> the time command to measure the time consumed but I also measure the
>> time within the C-code using clock() and get similar result. So the
>> Python startup time is not the reason for the runtime difference I
>> found. Thank you anyway.
> 
> We can't really help you much unless you give us more details about
> what you did (how did you built it, how did you time it, and how are
> you calling the C extension from Python).  All we can do is throw out
> possible ideas, and I will toss out a few, but if that's not it you'll
> have to post details.
> 
> Are you building the extension with the same optimization flags as the
> compiler?
> 
> Are you calling the C code repeatedly from inside a Python loop?
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python scripts with IIS

2008-01-19 Thread Rolf van de Krol
Adding the following lines before your print statement should do the 
trick. IIS complains about the headers, so adding headers should help.

print "Content-Type: text/html" # HTML is following
print   # blank line, end of headers



william paul wrote:
>  
> Hello:
>  
> I am trying to configure IIS to work with Python scripts:
>  
> I've added in the Home Directory/Configuration the .py extention and 
> the path to the python.exe as: c:\Python24\python.exe %S %S
> The python script has 1 line:
> print "This is a test for python scripts with IIS"
>  
> When I launch the file using IE I get the message:
>  
> *CGI Error*
> The specified CGI application misbehaved by not returning a complete 
> set of HTTP headers. The headers it did return are:
>  
> This is a test for python scripts with IIS
>  
> How can I remove the CGI error?
>  
> Thank you
>  
> William
>
> 
> Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try 
> it now. 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stdin, stdout, redmon

2008-01-21 Thread Rolf van de Krol
According to various tutorials this should work.


|import sys
data = sys.stdin.readlines()
print "Counted", len(data), "lines."|


Please use google before asking such questions. This was found with only 
one search for the terms 'python read stdin'

Rolf

Bernard Desnoues wrote:
> Hi,
>
> I've got a problem with the use of Redmon (redirection port monitor). I 
> intend to develop a virtual printer so that I can modify data sent to 
> the printer.
> Redmon send the data flow to the standard input and lauchs the Python 
> program which send modified data to the standard output (Windows XP and 
> Python 2.5 context).
> I can manipulate the standard output.
>
> "import sys
> sys.stdout.write(data)"
>
> it works.
> But how to manipulate standard input so that I can store data in a 
> string or in an object file ? There's no "read" method.
>
> "a = sys.stdin.read()" doesn't work.
> "f = open(sys.stdin)" doesn't work.
>
> I don't find anything in the documentation. How to do that ?
> Thanks in advance.
>
> Bernard Desnoues
> Librarian
> Bibliothèque de géographie - Sorbonne
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stdin, stdout, redmon

2008-01-21 Thread Rolf van de Krol
I don't know what you did with your Python installation, but for me this 
works perfectly.

test3.py contains:

import sys

print sys.stdin.readlines()


test.txt contains:

Testline1
Testline2


Output of 'python test3.py < test.txt' is:

['Testline1\n', 'Testline2']


Just plain simple and just works.

Rolf



Bernard Desnoues wrote:
> Rolf van de Krol a écrit :
>   
>> According to various tutorials this should work.
>>
>> 
>> |import sys
>> data = sys.stdin.readlines()
>> print "Counted", len(data), "lines."|
>> 
>>
>> Please use google before asking such questions. This was found with only 
>> one search for the terms 'python read stdin'
>>
>> Rolf
>>
>> Bernard Desnoues wrote:
>> 
>>> Hi,
>>>
>>> I've got a problem with the use of Redmon (redirection port monitor). 
>>> I intend to develop a virtual printer so that I can modify data sent 
>>> to the printer.
>>> Redmon send the data flow to the standard input and lauchs the Python 
>>> program which send modified data to the standard output (Windows XP 
>>> and Python 2.5 context).
>>> I can manipulate the standard output.
>>>
>>> "import sys
>>> sys.stdout.write(data)"
>>>
>>> it works.
>>> But how to manipulate standard input so that I can store data in a 
>>> string or in an object file ? There's no "read" method.
>>>
>>> "a = sys.stdin.read()" doesn't work.
>>> "f = open(sys.stdin)" doesn't work.
>>>
>>> I don't find anything in the documentation. How to do that ?
>>> Thanks in advance.
>>>
>>> Bernard Desnoues
>>> Librarian
>>> Bibliothèque de géographie - Sorbonne
>>>   
>
> Hello Rolf,
>
> I know this code because I have search a solution !
> Your google code doesn't work ! No attribute "readlines".
>
>  >>> import sys
>  >>> data = sys.stdin.readlines()
>
> Traceback (most recent call last):
>File "", line 1, in 
>  data = sys.stdin.readlines()
> AttributeError: readlines
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: stdin, stdout, redmon

2008-01-22 Thread Rolf van de Krol
Well, that's at least weird. I did test my code with Python 2.5 on Win 
XP, using the command prompt. But testing it with IDLE gives exactly the 
same error Bernard has. So apparently STDIN can't be accessed with IDLE.

Rolf

John Machin wrote:
>
> Excuse me, gentlemen, may I be your referee *before* you resort to
> pistols at dawn?
>
> = IDLE =
> IDLE 1.2.1
>   
>>>> import sys
>>>> sys.stdin.readlines
>>>> 
>
> Traceback (most recent call last):
>   File "", line 1, in 
> sys.stdin.readlines
> AttributeError: readlines
>   
>
> = Command Prompt =
> C:\junk>python
> Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>   
>>>> import sys
>>>> sys.stdin.readlines
>>>> 
> 
>   
>
> HTH,
> John
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Executing other python code

2008-01-28 Thread Rolf van de Krol
AFAIK this can't be done with just python. You can use the C API of 
Python to achieve this. I don't know the details of that, but I guess 
you will need this (http://docs.python.org/api/api.html).

Rolf

Tim Rau wrote:
> I'm working on a game, and I'd like players to be able to define thier
> ships with scripts. Naturally, I don't want to give them the entire
> program as thier romping ground. I would like to invoke a seperate
> interpreter for these files, and give it a limited subset of the
> functions in my game. What is the best way to achieve this effect?
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [2.4.2/Linux] Getting Python to fork?

2008-02-04 Thread Rolf van de Krol
To create a deamon, you indeed need to fork two times. For more 
information and a working example see: 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/278731 . I'm 
quite sure this works, because I used it several times to create a deamon.


Jon Ribbens wrote:
> On 2008-02-04, Christian Heimes <[EMAIL PROTECTED]> wrote:
>   
>>> Although bear in mind it's pretty UNIX-y.
>>>   
>> IIRC you have to fork a second time after you have changed the working
>> dir and created a new session group.
>> 
>
> Why? I don't think you do.
> Neither does BSD daemon.c or glibc daemon.c
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Write ooxml .ods (spreadsheat) from python?

2008-02-13 Thread Rolf van de Krol
Neal Becker wrote:
> I'd like to output some data directly in .ods format.  This format appears
> to be quite complex.  Is there any python software available to do this?  I
> did look at pyuno briefly.  It looks pretty complicated also, and it looks
> like it uses it's own private version of python, which would not help me.
>   
Google is your friend. For example this: 
http://www.oooforum.org/forum/viewtopic.phtml?p=56037#56037
It seems like that guy found the way to go for your problem.

Rolf

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reading a keypress

2008-02-25 Thread Rolf van de Krol
wyleu wrote:
> Aaah it doesn't work from idle but it does from the command line...
>
>   
You are right. You can't read STDIN from IDLE. There has been a topic 
about that before: 
http://groups.google.com/group/comp.lang.python/browse_thread/thread/9f9c90cfe52378fe

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is this valid ?

2008-03-20 Thread Rolf van de Krol
John Machin wrote:
> Of course. You can chain comparisons as much as you like and is
> (semi-)sensible, e.g.
>   
Hmm, 'of course' is not the correct word for it. Although the Stef 
Mientki would probably be able to find it in the documentation it is not 
as simple as you might think.
Most languages interpret a == b == 2 as (a == b) == 2, or throw an error 
because this syntax is not valid. The fact that python understand the 
obvious meaning of this code, is quite unique to Python, as far as I know.
-- 
http://mail.python.org/mailman/listinfo/python-list