Re: After migrating from debian to ubuntu, tkinter "hello world" doesn't work

2005-11-29 Thread Mandus
28 Nov 2005 11:02:57 -0800 skrev [EMAIL PROTECTED]:
> Hi
>
> My tkinter apps worked fine in debian linux (woody and sarge)
> I moved to ubuntu 5.10
>
> I follow the 'hello world' test as seen in
> http://wiki.python.org/moin/TkInter
>
>
> import _tkinter # with underscore, and lowercase 't'
> import Tkinter # no underscore, uppercase 'T'
> Tkinter._test() # note underscore in _test()

works just fine on my ubunty 5.10. Make sure you have the python2.4-tk
package installed (sudo apt-get install python2.4-tk).


-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: After migrating from debian to ubuntu, tkinter "hello world" doesn't work

2005-11-30 Thread Mandus
30 Nov 2005 04:23:37 -0800 skrev [EMAIL PROTECTED]:
>
> Mandus ha escrito:
>
>> works just fine on my ubunty 5.10. Make sure you have the python2.4-tk
>> package installed (sudo apt-get install python2.4-tk).
>>
>
> yes, i got it.
> It's a fresh instalation from a cd in a brand new laptop. I tried to
> reinstall python2.4-tk and many other packeges  :-(
>

If you think it may help, I can drop you my complete 
'dpkg --get-selections'. Just tell me where you want it.

mvh,
-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Favorite non-python language trick?

2005-06-25 Thread Mandus
Fri, 24 Jun 2005 16:31:08 +0100 skrev Tom Anderson:
> On Fri, 24 Jun 2005, Joseph Garvin wrote:
>
>> Claudio Grondi wrote:
>>
>> So far we've got lisp macros and a thousand response's to the lua trick. 
>> Anyone else have any actual non-python language tricks they like?
>
> Higher-order functions like map, filter and reduce. As of Python 3000, 
> they're non-python tricks. Sigh - i guess it's time for me to get to know 
> list comprehensions a bit better.
>

u-huu... I wasn't aware of that. It is really a consensus on this; that
removing map, filter, reduce is a good thing? It will render a whole lot
of my software unusable :(

Sure, I guess I can port most of it to list comprehensions, but
reduce/map are so much nicer.


-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Favorite non-python language trick?

2005-06-25 Thread Mandus
Sun, 26 Jun 2005 04:36:51 +1000 skrev Steven D'Aprano:
> On Sat, 25 Jun 2005 17:41:58 +0200, Konstantin Veretennicov wrote:
>
>> On 6/25/05, Mandus <[EMAIL PROTECTED]> wrote:
>>> It is really a consensus on this; that
>>> removing map, filter, reduce is a good thing? It will render a whole lot
>>> of my software unusable :(
>> 
>> I think you'll be able to use "from __past__ import map, filter,
>> reduce" or something like that :) They don't have to be built-in.
>
> More likely they will be moved to something like itertools than "__past__".
>
> Or just define them yourself:
>
> def map(f, seq):
> return [f(x) for x in seq]
>
> def filter(p, seq):
> return [x for x in seq if p(x)]
>
> def reduce(f, seq, zero):
> r = zero
> for x in seq: r = f(r, x)
> return r

sure - that will be possible. But the main point (for me) is to avoid
the horrible slow for-loop in python (reduce...). By using the builtin reduce, I
move the for-loop into the c-code which performs better. 

map and filter with list-comprehensions is probably ok - I use
list-comprehensions a lot, but somehow like the syntax of map/filter
better.

When it comes to lambdas, I am not so sure. I use them all the time, and
I will certainly miss them, and I have used lambdas in ways which at
least take som tinkering to translate to normal def's (or rather
closures). But I am not sure yet whether I have cases which are
impossible to translate (hey, nothing is impossible, some things just
take a bit more time).

Oh, and by the way, I use python to solve PDEs :)

But as someone else said, this will take some time. And I can always put
the c-function back in my self when that time comes.

Another important point, which it seems Guido does not fancy very much,
is that Python can be an ok functional style language for those who like
it. I very much enjoy the concept of using different programming styles
within the same language. It is mostly a convenience - I admit that -
but it makes me more productive. I'll be very sorry if we take that away
from python.

Maybe I am to late to change Guido on this - but if we are many, maybe
we can!

-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Favorite non-python language trick?

2005-06-25 Thread Mandus
Sat, 25 Jun 2005 16:06:57 GMT skrev Lee Harr:
>>> Higher-order functions like map, filter and reduce. As of Python 3000, 
>>> they're non-python tricks. Sigh - i guess it's time for me to get to know 
>>> list comprehensions a bit better.
>>>
>
>
> Couldnt there just be a "functional" module ?...
>
> from functional import map, filter, reduce

but lambda is grammar, so probably not so easy to import?


-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How does one write a function that increments a number?

2005-06-25 Thread Mandus
Sun, 26 Jun 2005 04:14:19 +1000 skrev Steven D'Aprano:
> On Fri, 24 Jun 2005 21:53:03 -0700, [EMAIL PROTECTED] wrote:
>
>>   Apologies if this question seems stupid: How does one write a
>> function that increments a value in Python? When I tried, the variable
>> never changed.
>> The session went like this:
>>>>> def incr(counter):
>>  counter = int(counter)
>>  counter += 1
>> 
>>>>> counter = 1
>>>>> incr(counter)
>>>>> print counter
>> 1
>
> Why does it need to be a function? Why complicate matters? Isn't it
> simpler to just do this:
[snip]

I guess he have some reason for it...

it's because python do call by value, not by reference for such simple
variables. 

If you absolutely want to do this, you can try:

def incr(counter):
   counter[0] += 1

counter=[1]
incr(counter)
print counter[0]

But I agree with Steven, this is probably not what you want to do :)

-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Favorite non-python language trick?

2005-06-25 Thread Mandus
Sat, 25 Jun 2005 21:30:26 +0200 skrev Peter Otten:
> Mandus wrote:
>
>> By using the builtin reduce, I
>> move the for-loop into the c-code which performs better.
>
> No. There is no hope of ever writing fast code when you do not actually
> measure its performance.

I do.

-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Favorite non-python language trick?

2005-06-25 Thread Mandus
25 Jun 2005 13:15:16 -0700 skrev Devan L:
> But by using the builtin reduce, you need to specify a function, which
> probably slows it down more than any speed-up from the loop in C.

Sounds reasonable, but not always the case, especially when dealing with
numpy arrays. At least that what some of my test shows. But then I
should probably write c-functions that deals with the numeric arrays
anyway. 

Besides, functions like 'operator.add' is also in c, maybe that helps.

But I admit it's not a perfect example.

-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Favorite non-python language trick?

2005-06-29 Thread Mandus
Sun, 26 Jun 2005 08:35:58 +0200 skrev Peter Otten:
> Steven D'Aprano wrote:
>
>> On Sat, 25 Jun 2005 21:30:26 +0200, Peter Otten wrote:
>> 
>>> Mandus wrote:
>>> 
>>>> By using the builtin reduce, I
>>>> move the for-loop into the c-code which performs better.
>>> 
>>> No. There is no hope of ever writing fast code when you do not actually
>>> measure its performance.
>> 
>> Good grief! You've been spying on Mandus! How else could you possibly know
>> that he doesn't measure performance? Are you running a key-logger on his
>> machine? *wink*
>
> His mentioning reduce() as a performance panacea was a strong indication
> even without looking over his shoulders. He filled in some conditions in a
> later post, but "[U]sing reduce ... performs better [than a for-loop]" is
> just wrong.

Ok - so sometimes reduce() for convenience (nha, that's just me...),
sometimes for performance. In some cases clever use of map/reduce/etc.
have given a good speedup - say  4 times that of for-loops. But going to
C can give 10 to 100 times speed up over that again... So it depends how
important the performance is. Going to C/Fortran is always a bit more
hassel, while reduce is something you can stick in your interactive
session to finish the work rather before than after lunch :)

[snip]
>
>> Isn't it reasonable to just say, "I use join because it is faster than
>> adding strings" without being abused for invalid optimization?
>
> OK, I am making a guess: "".join(strings) is more often faster than
> naive string addition than reduce() wins over a for-loop.

you're probably right.

> I don't think my pointed comment qualifies as "abuse", by the way.

neither think I.


-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


map vs. list-comprehension

2005-06-29 Thread Mandus
Hi there,

inspired by a recent thread where the end of reduce/map/lambda in Python was
discussed, I looked over some of my maps, and tried to convert them to
list-comprehensions.

This one I am not sure how to conver:

Given three tuples of length n, b,i and d, I now do:

map(lambda bb,ii,dd: bb+ii*dd,b,i,d)

which gives a list of length n. 

Anyone have an idea what the equivalent list comprehension will be?

take care,
-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: map vs. list-comprehension

2005-06-29 Thread Mandus
29 Jun 2005 10:04:40 GMT skrev F. Petitjean:
> Le Wed, 29 Jun 2005 09:46:15 + (UTC), Mandus a écrit :
>> Hi there,
>>
>> inspired by a recent thread where the end of reduce/map/lambda in Python was
>> discussed, I looked over some of my maps, and tried to convert them to
>> list-comprehensions.
>>
>> This one I am not sure how to conver:
>>
>> Given three tuples of length n, b,i and d, I now do:
>>
>> map(lambda bb,ii,dd: bb+ii*dd,b,i,d)
>>
>> which gives a list of length n. 
>
> res = [ bb+ii*dd for bb,ii,dd in zip(b,i,d) ]

aha - thanks! I wasn't aware of zip. Guess I have to put python in a
nutshell on my nightstand (again) :-)

seem to be a tad slower than the map, but nothing serious. Guess it's
the extra zip.

>
> Hoping that zip will not be deprecated.

hopefully not...

-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: map vs. list-comprehension

2005-06-30 Thread Mandus
Wed, 29 Jun 2005 08:33:58 -0700 skrev Scott David Daniels:
> Mandus wrote:
>> 29 Jun 2005 10:04:40 GMT skrev F. Petitjean:
>> 
>>>Le Wed, 29 Jun 2005 09:46:15 + (UTC), Mandus a écrit :
>>>
>>>res = [ bb+ii*dd for bb,ii,dd in zip(b,i,d) ]
>> 
>> seem to be a tad slower than the map, but nothing serious. Guess it's
>> the extra zip.
> You could try timing it using itertools.izip rather than zip.

jepp - faster, but still slower than the map.

100 iterations:
 zip+list-comprehension: 8.1s
 izip+list-comprehension: 7.5s
 map: 7.0s

-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C++, Swig, and pyMPI

2005-08-02 Thread Mandus
2 Aug 2005 03:47:02 -0700 skrev stringy:
> I would like to be able to write a C++ function, to be wrapped into
> some python, to be able to communicate over pyMPI. As pyMPI is based on
> C++ I figure that this should be possible, although I'm not sure of
> where to start. I know the basics of swig and pyMPI, but not how I
> would do this.
>
> Does anyone know if this is possible and where to start?
>

Are you sure that pyMPI are C++-based? I think it is based on pure C?

Besides that, it is not clear (at least to me) what you try to achive.
Do you want to use MPI also in your extension module?

mvh,
-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pain

2005-08-03 Thread Mandus
Wed, 03 Aug 2005 17:45:34 +0200 skrev Mage:
>   Hello,
>
> I started to learn python some months ago. Mostly for fun, but I 
> replaced php to python in many tools at my company in the last weeks.
>
> Because of our boss decision now I have to learn java. I can tell java 
[snip]

maybe you can use jython, and tell your boss it's Java. A boss forcing
people to learn and use Java probably have no interest at all ever read
the code himself, so you will probably get away with it. I mean, a
clueless boss...

or just find another place to work?

Don't code Java, be happy :-)

mvh,
-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: socket and os.system

2005-08-03 Thread Mandus
Wed, 03 Aug 2005 15:46:50 - skrev mfaujour:
>
> I HAVE THIS PYTHON PROGRAMM:
>  
[snip]

welcome to usenet!

Maybe you get an answer if you doesn't shout that much. Or maybe you
just have a problem with you Caps Lock?


-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numarray :: multiplying all the elements in 1d array

2005-12-20 Thread Mandus
Tue, 20 Dec 2005 19:32:13 +0530 skrev Suresh Jeevanandam:
> Hi all,
>   Lets say I have an array:
>   from numarray import *
>   a = array([ 6,  7,  8,  9, 10, 11, 12])
>
>   I want to multiply out all the elements and get the result.
>   
>   r = 1.0
>   for i in a:
>   r = r*i
>
>   Is there any faster, efficient way of doing this.

You can use multiply.reduce(a) (multiply is a function imported from
numarray).

With regular python you can also do:

from operator import mul
reduce(mul,a)

This work even when 'a' is a plain python list.


-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Computer Cluster Python Software

2005-06-06 Thread Mandus
6 Jun 2005 07:22:54 -0700 skrev uli:
> Is there any open source Python software (preferably biopython) written
> which runs on a cluster.  Alternatively are there interfaces written in
> Python to existing cluster software.

Can you be more specific? There are for example several MPI interfaces
(pyMPI, pypar, ScientificPython.MPI). With pyMPI, you can run python
interactively on a cluster if you want. 

But you are probably looking for something else?

btw, soon there will be PyFDM (pyfdm.sf.net) which will make it possible
to do FDM on a cluster (or any parallel computer) with little effort.

mvh,
-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Abstract and concrete syntax

2005-06-10 Thread Mandus
As someone who like to do functional style programming, but without a
lot of training in that dept., I miss what you ask for from time to
time.

I don't want to go to much into this discussion, just comment on a tiny
little bit:

Thu, 09 Jun 2005 03:32:12 +0200 skrev David Baelde:
[snip]
>
> set_callback(obj,
>  lambda x: (if a:
>2
>  else:
>3)
>
[snip]

You can do stuff like this: lambda x: x and 2 or 3

Of course, you are still quite limited in what you can do, but it have
solved some of my problems...

mvh,
-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C++ and Python

2007-03-09 Thread Mandus
8 Mar 2007 22:04:48 -0800 skrev [EMAIL PROTECTED]:
> Hi Everyone,
>
> I'm considering about generating some Python Bindings for C++
> libraries. What are considered the best tools for doing something like
> this? I know that there are SWIG, SIP, Boost.Python, and GCC_XML.

We are doing this quite extensively at work, and have found that in the
long run SWIG is the best solution. OMMV, but if you ask me, the answer
is SWIG. 

mvh,
-- 
Mandus - the only mandus around.
-- 
http://mail.python.org/mailman/listinfo/python-list