Encryption source code with md5

2010-03-28 Thread catalinf...@gmail.com
Dear friends .

I have two simple questions:
It is possible to encrypt with md5 python source code?
What option do I have to protect my python source code?

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


Re: GIF89A and PIL

2010-03-28 Thread garabik-news-2005-05
Harishankar  wrote:
> 
>> Just opening, and then saving the same file with no changes at all,
>> resulted in a 72 byte file growing to 920.
>> 
>> I thought it was GIF87a vs GIF89a... but have since come to determine it
>> doesn't appear to be. I decided to give PNG a try again, since those
>> extra 50 bytes *matter*, but if I can't get GIF to work, 50 is better
>> then 900. Unfortunately, I hit the same wall there.
>> 
 
> Also try the pngcrush utility and see what size it gives you.
> http://pmt.sourceforge.net/pngcrush/
>

optipng gives slightly better results. 

Anyway, depending on your pictures, you might find out that using
*.ppm.gz, *.pgm.gz or *.pbm.gz outperforms both optimised gif ad png...
and if sending more pictures down the line, tar-ing them (*.p?m) and
compressing the result will give even better sizes.


-- 
 ---
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encryption source code with md5

2010-03-28 Thread alex goretoy
There's not many options when it comes to obfuscating python source. If you
even do find a way to obfuscate it. It won't take much to reverse it. That's
just how python works. Really I wouldn't even worry about looking for a way
to do this, reason behind that is that it's not difficult to reverse it.
This is not c,c++, php or java man/woman. Good luck.

Thank you,
-Alex Goretoy
http://launchpad.net/~a1g


On Sun, Mar 28, 2010 at 12:59 AM, catalinf...@gmail.com <
catalinf...@gmail.com> wrote:

> Dear friends .
>
> I have two simple questions:
> It is possible to encrypt with md5 python source code?
> What option do I have to protect my python source code?
>
> Thank you .
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encryption source code with md5

2010-03-28 Thread starglider develop
py2exe

On 28 March 2010 07:59, catalinf...@gmail.com  wrote:

> Dear friends .
>
> I have two simple questions:
> It is possible to encrypt with md5 python source code?
> What option do I have to protect my python source code?
>
> Thank you .
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encryption source code with md5

2010-03-28 Thread Lawrence D'Oliveiro
In message <91541c26-6f18-40c7-
a0df-252a52bb7...@l25g2000yqd.googlegroups.com>, catalinf...@gmail.com 
wrote:

> It is possible to encrypt with md5 python source code?

Don’t use MD5.

> What option do I have to protect my python source code?

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


Re: Classes as namespaces?

2010-03-28 Thread News123
Hi STephen,

Stephen Hansen wrote:

> That said...
> 
>> [*] My own subjective dislike for the widespread practice of using
>> triple quotes to comment out code is formally similar to this one
>> ("the 'intended use' for triple-quoting is not to comment out code",
>> etc.).  Here I find myself on the opposite side of the purist/pragmatic
>> divide.  Hmmm.
> 
> What?!
> 
> Where do you get this "widespread practice"? You mentioned that before
> when you last posted about that and I forgot to comment. I've never seen
> it.
I wouldn't say it's wide spread, but definitely something one
encounters. Especially with python rather new to python
> 
> In the 110k lines of in-house code I maintain, we don't use it once; we
> have somewhere around 300k lines of third-party code from a wide range
> of sources, and although I haven't reviewed it all by any means, I
> regularly have to peek over it and I never seen triple quoted "comments".
> 
> Hell, I almost never see commented -code-. Code should only be commented
> while fiddling or debugging. Once fiddlng is done, dead code should be
> removed.
> 
> I'm sure it -happens- every once in awhile, but.. why? Who uses editors
> that can't block comment/uncomment anymore? :(

I had to explain block comment / uncomment to some collegues before the
triple quote commenting disappeared from our code.
Unfortunaltely everybody uses a different type of editor, so I googled
for them to show them what their editors can do.

You'd be surprised how many people do neither master their editors nor
care for it.

bye

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


Re: Programmatically discovering encoding types supported by codecs module

2010-03-28 Thread python
Gabriel,

Thank you for your analysis - very interesting. Enjoyed your fromlist
choice of names. I'm still in my honeymoon phase with Python so I only
know the first part :)

Regards,
Malcolm


- Original message -
From: "Gabriel Genellina" 
To: python-list@python.org
Date: Wed, 24 Mar 2010 19:50:11 -0300
Subject: Re: Programmatically discovering encoding types supported by
codecsmodule

En Wed, 24 Mar 2010 14:58:47 -0300,  escribió:

>> After looking at how things are done in codecs.c and  
>> encodings/__init__.py  I think you should enumerate all modules in the  
>> encodings package that define a getregentry function. Aliases come from  
>> encodings.aliases.aliases.
>
> Thanks for looking into this for me. Benjamin Kaplan made a similar
> observation. My reply to him included the snippet of code we're using to
> generate the actual list of encodings that our software will support
> (thanks to Python's codecs and encodings modules).

I was curious as whether both methods would give the same results:

py> modules=set()
py> for name in glob.glob(os.path.join(encodings.__path__[0], "*.py")):
...   name = os.path.basename(name)[:-3]
...   try: mod = __import__("encodings."+name,  
fromlist=['ilovepythonbutsometimesihateit'])
...   except ImportError: continue
...   if hasattr(mod, 'getregentry'):
... modules.add(name)
...
py> fromalias = set(encodings.aliases.aliases.values())
py> fromalias - modules
set(['tactis'])
py> modules - fromalias
set(['charmap',
  'cp1006',
  'cp737',
  'cp856',
  'cp874',
  'cp875',
  'idna',
  'iso8859_1',
  'koi8_u',
  'mac_arabic',
  'mac_centeuro',
  'mac_croatian',
  'mac_farsi',
  'mac_romanian',
  'palmos',
  'punycode',
  'raw_unicode_escape',
  'string_escape',
  'undefined',
  'unicode_escape',
  'unicode_internal',
  'utf_8_sig'])

There is a missing 'tactis' encoding (?) and about twenty without alias.

-- 
Gabriel Genellina

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

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


Need help with using SOAP based web service

2010-03-28 Thread Arun Balagopal
Hi,
I am working on a project in text mining using Python. As part of the
project I need to use a technical term extractor, and I found the
Terminesystem from
NACTEM very useful. I have used the web demo (it's pretty nifty)
and now want to integrate it in my project. The service provides a SOAP
interface, which I am trying to use in Python with the ZSI 2.0 module (I
have never used it before). The sample client scripts and instructions for
Python are provided here

Here's what I did. I installed ZSI 2.0 and its dependency PyXml. Then as
given in the instructions, I generated wrappers for the service (2 python
files). However when I try to run the sample script, I get errors (something
about no attribute 'typecode'). I have tried tweaking in the source, but
still no luck.

If anybody knows how exactly to get this thing working, please help. I am
new to the mailing list, and I apologize if this is the wrong place to post
such questions.

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


Re: Encryption source code with md5

2010-03-28 Thread Irmen de Jong

On 28-3-2010 12:08, Lawrence D'Oliveiro wrote:

In message<91541c26-6f18-40c7-
a0df-252a52bb7...@l25g2000yqd.googlegroups.com>, catalinf...@gmail.com
wrote:


It is possible to encrypt with md5 python source code?


Don’t use MD5.


Also, md5 is not an encryption algorithm at all, it is a secure hashing 
function.
(well, not so secure anymore nowadays, which probably is why Lawrence already wrote to 
avoid using it).


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


AUTHENTIC DESIGNER HANDBAGS ACCESSORIES GREAT DISCOUNTS! WWW.VOGUELANDE.COM

2010-03-28 Thread Rolla
Dear Customer,

We now have NEW ARRIVAL accessories coming. Please check the site as
follows,

http://www.voguelande.com/ChanelAcce.html

http://www.voguelande.com/Accessories.html

CONTACT INFO: i...@voguelande.com
-- 
http://mail.python.org/mailman/listinfo/python-list


رجل حامل في الكويت !!! صور

2010-03-28 Thread اااالوافي
http://www.nb11.net/vb/forumdisplay.php?f=25
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encryption source code with md5

2010-03-28 Thread catalinf...@gmail.com
I had a talk about Python and distribution of commercial products
created with python. This made me think of a way to protect my source
code to be distributed. I thought a live CD version and then to an
encryption method of a portion of source code. These thoughts are the
source of two questions.
-- 
http://mail.python.org/mailman/listinfo/python-list


map, index

2010-03-28 Thread Luis Quesada

Dear all,

I am new to Python, so I apologize in advance if you find my questions 
naive (or if they have been already answered in this forum).


1. What is the most pythonic way of mapping a list where the value each 
element is mapped to depends on the index of the element. Is there a way 
of writing the following without using zip:

map(lambda (id,v):id*v,zip(range(len(L)),L))
I wonder whether there is something like mapInd in Oz 
(http://www.mozart-oz.org/documentation/base/list.html) so that you can 
pass a binary function to map and refer to the index of the element in 
the body of the given function. It would be cool to be able to simply write:

mapInd(lambda id,v:id*v,L)

2. Is there a higher order index function that lets you specify the 
condition to be met by the returned element. I mean something like:


def my_index(f,L,default):
for x in L:
if f(x):return x
return default

Thanks in advance for your answer!

Cheers,
Luis
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Traits Questions

2010-03-28 Thread Ethan Furman

Robert Kern wrote:

On 2010-03-27 08:19 , Ethan Furman wrote:


Okay, different post for my actual questions.  :)

On the PyPI page for strait (http://pypi.python.org/pypi/strait/0.5.1)
it has the example of choosing which methods to keep in the composed 
class:


class TOSWidget(BaseWidget):
__metaclass__ = include(Pack, Place, Grid)
info = Pack.info.im_func
config = Pack.config.im_func
configure = Pack.configure.im_func
slaves = Pack.slaves.im_func
forget = Pack.forget.im_func
propagate = Pack.propagate.im_func

My question is:

Why use

info = Pack.info.im_func

instead of

info = Pack.info

?



Pack.info is an unbound method object attached to the Pack class, not a 
function object. It has some extra semantics on top of functions and is 
tied to the Pack class. The .im_func attribute gets the actual function 
object underneath. When defining the TOSWidget class, the objects 
defined in the suite under the class: statement need to be actual 
functions in order to be turned into unbound methods attached to the 
TOSWidget class.


Ah, thank you.

In Python 3, though, would the Pack.info form be correct?

~Ethan~

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


Re: map, index

2010-03-28 Thread Duncan Booth
Luis Quesada  wrote:

> Is there a way 
> of writing the following without using zip:
>  map(lambda (id,v):id*v,zip(range(len(L)),L))

[ id*v for id,v in enumerate(L) ]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encryption source code with md5

2010-03-28 Thread Steve Holden
catalinf...@gmail.com wrote:
> I had a talk about Python and distribution of commercial products
> created with python. This made me think of a way to protect my source
> code to be distributed. I thought a live CD version and then to an
> encryption method of a portion of source code. These thoughts are the
> source of two questions.

I'd suggest that you don't think about encrypting your source code until
you have a rather better handle on encryption technology. Your mention
of MD5, a hashing rather than an encryption algorithm, makes it clear
that you aren't familiar with the technologies at present.

There's nothing wrong with ignorance (I have a more than adequate supply
of my own), but in encryption it's *very* easy to make mistakes that
render whole systems vulnerable to trivial attack. So you do really need
to know what you are doing.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
See PyCon Talks from Atlanta 2010  http://pycon.blip.tv/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

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


Re: sum for sequences?

2010-03-28 Thread Steve Howell
On Mar 27, 3:18 am, Steven D'Aprano  wrote:
> On Fri, 26 Mar 2010 07:31:17 -0700, Steve Howell wrote:
> > From a purely academic standpoint, I'm not convinced that sum() is
> > inefficient in terms of big-O complexity, though.
>
> >  show...@showell-laptop:~$ python
> >  Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on
> >  linux2
> >  >>> class StupidList:
>
> [...]
>
> But it's not *sum* that is inefficient, it is sum *with a particular data
> structure*.
>

Yep, the implied context was with particular data structures.

> Sure, if you create your own data structure, you can make it as efficient
> as you like. Obviously the sum algorithm itself has to perform one
> addition per item, or O(N), which scales tolerably well. But each
> addition has a cost. If the cost is constant, then sum() as a whole
> remains O(N). But if the cost of addition varies with N, sum() degrades
> ba
>

The surprising part of sum() is not that the outer loop to do the sums
is O(N).  It is hard to imagine any other implementation (without
parallelizing it).

The mildly surprising part of sum() is that is does add vs. add-in-
place, which leads to O(N) vs. O(1) for the inner loop calls, for
certain data structures, notably lists, even though none of the
intermediate results get used by the caller.  For lists, you could
make a more efficient variant of sum() that clones the start value and
does add-in-place.

I could guess pretty confidently that the reason this optimization was
never tried is that sum() has always been intended to be used on
numerics, since other alternatives exist for strings (join), lists
(chain), and hand-coded data classes that support add-in-place (roll-
your-own loop).

The documentation is pretty clear on the intention that sum() is
intended for numbers:

http://docs.python.org/library/functions.html#sum

Except for strings, the docs are not explicit about efficiency
concerns for other data structures, or the fact that the reference
implementation does add vs. add-in-place under the hood.




http://docs.python.org/library/functions.html#sum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function decorator-like function

2010-03-28 Thread Michele Simionato
Another option is to use my own decorator module (http://
pypi.python.org/pypi/decorator):

from decorator import decorator

@decorator
def d(func, *args):
print 3
return func(*args)

@d
def f(a, b):
print a + b

f(5, 7)


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


Re: map, index

2010-03-28 Thread Luis Quesada

Duncan Booth wrote:

Luis Quesada  wrote:

Is there a way 
of writing the following without using zip:

 map(lambda (id,v):id*v,zip(range(len(L)),L))


[ id*v for id,v in enumerate(L) ]

Cool! Thanks!
Cheers,
Luis
--
http://mail.python.org/mailman/listinfo/python-list


Re: Encryption source code with md5

2010-03-28 Thread Harishankar
On Sun, 28 Mar 2010 10:08:20 -0400, Steve Holden wrote:

> catalinf...@gmail.com wrote:
>> I had a talk about Python and distribution of commercial products
>> created with python. This made me think of a way to protect my source
>> code to be distributed. I thought a live CD version and then to an
>> encryption method of a portion of source code. These thoughts are the
>> source of two questions.
> 
> I'd suggest that you don't think about encrypting your source code until
> you have a rather better handle on encryption technology. Your mention
> of MD5, a hashing rather than an encryption algorithm, makes it clear
> that you aren't familiar with the technologies at present.
> 
> There's nothing wrong with ignorance (I have a more than adequate supply
> of my own), but in encryption it's *very* easy to make mistakes that
> render whole systems vulnerable to trivial attack. So you do really need
> to know what you are doing.
> 
> regards
>  Steve

This article offers some good ideas and also sums up some good points 
*against* code obfuscation.

http://stackoverflow.com/questions/261638/how-do-i-protect-python-code

Read it and judge whether the benefits of not obfuscating code outweighs 
the advantages of obfuscating it.





-- 
Harishankar (http://harishankar.org http://literaryforums.org)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sum for sequences?

2010-03-28 Thread Steven D'Aprano
On Sun, 28 Mar 2010 07:16:10 -0700, Steve Howell wrote:

> The mildly surprising part of sum() is that is does add vs. add-in-
> place, which leads to O(N) vs. O(1) for the inner loop calls, for
> certain data structures, notably lists, even though none of the
> intermediate results get used by the caller.  For lists, you could make
> a more efficient variant of sum() that clones the start value and does
> add-in-place.

I have no doubt that you could make a version of sum for lists which is 
more efficient than the existing one. After all, join more or less does 
the same sort of thing, and it's very efficient. But don't think that add-
in-place is necessarily cheap. List appends are amortized O(1) each; if 
you are adding M lists of N items each, that gives you O(M*N).

It's possible to improve the performance a tad if you can make multiple 
appends in roughly constant time, which is what list.extend (probably?) 
does, but only up to a point. Lists are over-allocated, but if you try to 
add more items than there is room for, you need to make the list bigger, 
and that means reallocating memory, which could easily be O(N**2) or 
worse, depending on how good your OS's memory management is. Under Linux, 
at least by default, malloc will never fail, but there's no guarantee how 
long it will take to return. If the OOM killer has to start shutting down 
other applications, and paging more and more memory to disk, eventually 
malloc will return (or the system will core dump), but it could take a 
while...



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


Re: Encryption source code with md5

2010-03-28 Thread Steven D'Aprano
On Sun, 28 Mar 2010 10:08:20 -0400, Steve Holden wrote:

> catalinf...@gmail.com wrote:
>> I had a talk about Python and distribution of commercial products
>> created with python. This made me think of a way to protect my source
>> code to be distributed. I thought a live CD version and then to an
>> encryption method of a portion of source code. These thoughts are the
>> source of two questions.
> 
> I'd suggest that you don't think about encrypting your source code until
> you have a rather better handle on encryption technology. Your mention
> of MD5, a hashing rather than an encryption algorithm, makes it clear
> that you aren't familiar with the technologies at present.

Furthermore, you should forget about encrypting your program until you 
are sure that it is something that needs encrypting. In my experience, 
most times newbies start waffling on about encrypting their precious code 
(usually displaying total confusion about encryption technology), it 
turns out their critical application is something like Notepad only with 
fewer features.

Not that I'm jaded at all.



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


Re: StringChain -- a data structure for managing large sequences of chunks of bytes

2010-03-28 Thread Steven D'Aprano
On Sun, 28 Mar 2010 06:48:21 +1100, Lie Ryan wrote:

> On 03/22/2010 07:07 PM, Steven D'Aprano wrote:
>> Perhaps you should have said that it was a wrapper around deque giving
>> richer functionality, rather than giving the impression that it was a
>> brand new data structure invented by you. People are naturally going to
>> be more skeptical about a newly invented data structure than one based
>> on a reliable, component like deque.
> 
> Well, technically StringChain is not a data structure in the first
> place. StringChain is a string;

And strings are data structures, as are arrays and structs. Just because 
they're simple data structures made directly from primitives rather than 
rich, complex structures, doesn't mean they're not data structures.


> a string that is implemented using deque
> data structure to make appending algorithmically efficient. It is not a
> data structure, in the sense that I can't put arbitrary "thing" into the
> data structure. 

Any "thing" that can be pickled or serialised can be put into a string.



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


Re: sum for sequences?

2010-03-28 Thread Duncan Booth
Steve Howell  wrote:

> The mildly surprising part of sum() is that is does add vs. add-in-
> place, which leads to O(N) vs. O(1) for the inner loop calls, for
> certain data structures, notably lists, even though none of the
> intermediate results get used by the caller.  For lists, you could
> make a more efficient variant of sum() that clones the start value and
> does add-in-place.

Doing add-in-place isn't the only way to make sum more efficient: if you 
assume that addition is associative (which of course the builtin sum can't) 
then you can form partial sums. e.g. instead of calculating:

  (((a + b) + c) + d) + e) + f) + g) + h)

you calculate:

  (((a + b) + (c + d)) + ((e + f) + (g + h)))

Obviously this requires more space than the naive sum, but not as much as 
you might at first expect: you only need to hold log(n) intermediates 
values at any time.

> I could guess pretty confidently that the reason this optimization was
> never tried is that sum() has always been intended to be used on
> numerics, since other alternatives exist for strings (join), lists
> (chain), and hand-coded data classes that support add-in-place (roll-
> your-own loop).

Doing it this way helps summing lists or strings (though not as much as 
str.join), but it also helps if you need to sum a long list of similarly 
sized floats as you'll get a more accurate answer.

See 
http://groups.google.com/group/comp.lang.python/browse_thread/thread/9eda29
faf92f532e/027cef7d4429aa3a
for an earlier discussion of this, or just Google comp.lang.python for 
'pairwise sum'.

Here's the code I posted in that thread:

def sumpairs(seq): 
tmp = [] 
for i,v in enumerate(seq): 
if i&1: 
tmp[-1] = tmp[-1] + v 
i = i + 1 
n = i & -i 
while n > 2: 
t = tmp.pop(-1) 
tmp[-1] = tmp[-1] + t 
n >>= 1 
else: 
tmp.append(v) 
while len(tmp) > 1: 
t = tmp.pop(-1) 
tmp[-1] = tmp[-1] + t 
return tmp[0] 

and I claimed that my Python coded sumpairs function was faster than the 
builtin sum on a list of lists once you had more than about 210 items.
I never did get round to rewriting it in C for a more realistic speed 
comparison: summing integers my Python version is about 60 times slower 
than the builtin.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sum for sequences?

2010-03-28 Thread Steve Howell
On Mar 28, 8:17 am, Duncan Booth  wrote:
> Steve Howell  wrote:
> > The mildly surprising part of sum() is that is does add vs. add-in-
> > place, which leads to O(N) vs. O(1) for the inner loop calls, for
> > certain data structures, notably lists, even though none of the
> > intermediate results get used by the caller.  For lists, you could
> > make a more efficient variant of sum() that clones the start value and
> > does add-in-place.
>
> Doing add-in-place isn't the only way to make sum more efficient: if you
> assume that addition is associative (which of course the builtin sum can't)
> then you can form partial sums. e.g. instead of calculating:
>
>   (((a + b) + c) + d) + e) + f) + g) + h)
>
> you calculate:
>
>   (((a + b) + (c + d)) + ((e + f) + (g + h)))
>
> Obviously this requires more space than the naive sum, but not as much as
> you might at first expect: you only need to hold log(n) intermediates
> values at any time.
>

Yep, I did mention in my post that the outer loop does not *have* to
be O(N), if you can parallelize it.  Apart from reducing
intermediates, the divide-and-conquer method does not reduce overall
computation time unless you have multiple processors, correct?

> > I could guess pretty confidently that the reason this optimization was
> > never tried is that sum() has always been intended to be used on
> > numerics, since other alternatives exist for strings (join), lists
> > (chain), and hand-coded data classes that support add-in-place (roll-
> > your-own loop).
>
> Doing it this way helps summing lists or strings (though not as much as
> str.join), but it also helps if you need to sum a long list of similarly
> sized floats as you'll get a more accurate answer.
>

Interesting!  That makes sense.  The docs for math.fsum() suggest that
partial sums are used to maintain precision.

http://docs.python.org/library/math.html#math.fsum

> Seehttp://groups.google.com/group/comp.lang.python/browse_thread/thread/...
> faf92f532e/027cef7d4429aa3a
> for an earlier discussion of this, or just Google comp.lang.python for
> 'pairwise sum'.
>
> Here's the code I posted in that thread:
>
> def sumpairs(seq):
>     tmp = []
>     for i,v in enumerate(seq):
>         if i&1:
>             tmp[-1] = tmp[-1] + v
>             i = i + 1
>             n = i & -i
>             while n > 2:
>                 t = tmp.pop(-1)
>                 tmp[-1] = tmp[-1] + t
>                 n >>= 1
>         else:
>             tmp.append(v)
>     while len(tmp) > 1:
>         t = tmp.pop(-1)
>         tmp[-1] = tmp[-1] + t
>     return tmp[0]
>
> and I claimed that my Python coded sumpairs function was faster than the
> builtin sum on a list of lists once you had more than about 210 items.
> I never did get round to rewriting it in C for a more realistic speed
> comparison: summing integers my Python version is about 60 times slower
> than the builtin.

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


Why this Difference in Importing NumPy 1.2 vs 1.4?

2010-03-28 Thread W. eWatson
I wrote a program in Python 2.5 under Win7 and it runs fine using Numpy 
1.2 , but not on a colleague's machine who has a slightly newer 2.5 and 
uses NumPy 1.4. We both use IDLE to execute the program. During import 
he gets this:


>>>
Traceback (most recent call last):
  File "C:\Documents and Settings\HP_Administrator.DavesDesktop\My 
Documents\Astro\Meteors\NC-FireballReport.py", line 38, in 

from scipy import stats as stats # scoreatpercentile
  File "C:\Python25\lib\site-packages\scipy\stats\__init__.py", line 7, 
in 

from stats import *
  File "C:\Python25\lib\site-packages\scipy\stats\stats.py", line 191, 
in 

import scipy.special as special
  File "C:\Python25\lib\site-packages\scipy\special\__init__.py", line 
22, in 

from numpy.testing import NumpyTest
ImportError: cannot import name NumpyTest
>>>

Comments?

It looks as though the problem is in NumPy 1.4. If it's either in NumPy 
or SciPy, how does my colleague back out to an earlier version to agree 
with mine? Does he just pull down 1.3 or better 1.2 (I use it.), and 
install it? How does he somehow remove 1.4? Is it as easy as going to 
IDLE's path browser and removing, under site-packages, numpy? (I'm not 
sure that's even possible. I don't see a right-click menu.)

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


Re: sum for sequences?

2010-03-28 Thread Steve Howell
On Mar 28, 7:57 am, Steven D'Aprano  wrote:
> On Sun, 28 Mar 2010 07:16:10 -0700, Steve Howell wrote:
> > The mildly surprising part of sum() is that is does add vs. add-in-
> > place, which leads to O(N) vs. O(1) for the inner loop calls, for
> > certain data structures, notably lists, even though none of the
> > intermediate results get used by the caller.  For lists, you could make
> > a more efficient variant of sum() that clones the start value and does
> > add-in-place.
>
> I have no doubt that you could make a version of sum for lists which is
> more efficient than the existing one. After all, join more or less does
> the same sort of thing, and it's very efficient. But don't think that add-
> in-place is necessarily cheap. List appends are amortized O(1) each; if
> you are adding M lists of N items each, that gives you O(M*N).
>

O(M*N) is still cheaper than O(M*N*N).

> It's possible to improve the performance a tad if you can make multiple
> appends in roughly constant time, which is what list.extend (probably?)
> does, but only up to a point. Lists are over-allocated, but if you try to
> add more items than there is room for, you need to make the list bigger,
> and that means reallocating memory, which could easily be O(N**2) or
> worse, depending on how good your OS's memory management is. Under Linux,
> at least by default, malloc will never fail, but there's no guarantee how
> long it will take to return. If the OOM killer has to start shutting down
> other applications, and paging more and more memory to disk, eventually
> malloc will return (or the system will core dump), but it could take a
> while...
>

Even though extend() obviously has to do memory allocations along the
way itself, it is still more efficient than the alternative.  No need
to speculate, you can measure these methods on your platform:

M = 10
N = 1000

def in_place(
start = [],
sublists = ([[None] * M]) * N
):
accum = start[:]
for sublist in sublists:
accum.extend(sublist)
return accum

def with_intermediates(
start = [],
sublists = ([[None] * M]) * N
):
accum = start
for sublist in sublists:
accum = accum + sublist
return accum
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function decorator-like function

2010-03-28 Thread Patrick Maupin
On Mar 28, 9:17 am, Michele Simionato 
wrote:
> Another option is to use my own decorator module (http://
> pypi.python.org/pypi/decorator):
>
> from decorator import decorator
>
> @decorator
> def d(func, *args):
>     print 3
>     return func(*args)
>
> @d
> def f(a, b):
>     print a + b
>
> f(5, 7)

That looks cool (and I'm glad you mentioned it), but it appeared to me
the OP was trying to manually construct the equivalent of a decorator
without the "@" syntax, in order to gain an understanding of how
decorators work, and for this particular purpose, piling additional
magic on top of decorators is probably not helpful :-)

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


Re: sum for sequences?

2010-03-28 Thread Patrick Maupin
On Mar 28, 10:17 am, Duncan Booth 
wrote:
> Doing add-in-place isn't the only way to make sum more efficient: if you
> assume that addition is associative (which of course the builtin sum can't)
> then you can form partial sums. e.g. instead of calculating:
...
>
> Doing it this way helps summing lists or strings (though not as much as
> str.join), but it also helps if you need to sum a long list of similarly
> sized floats as you'll get a more accurate answer.

Also, partial sums would be a clear winner over add-in-place if
someone were dumb^H^H^H^Hnaive enough to use sum() on a long list of
tuples :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sum for sequences?

2010-03-28 Thread Alf P. Steinbach

* Steve Howell:

On Mar 28, 8:17 am, Duncan Booth  wrote:

Steve Howell  wrote:

The mildly surprising part of sum() is that is does add vs. add-in-
place, which leads to O(N) vs. O(1) for the inner loop calls, for
certain data structures, notably lists, even though none of the
intermediate results get used by the caller.  For lists, you could
make a more efficient variant of sum() that clones the start value and
does add-in-place.

Doing add-in-place isn't the only way to make sum more efficient: if you
assume that addition is associative (which of course the builtin sum can't)
then you can form partial sums. e.g. instead of calculating:

  (((a + b) + c) + d) + e) + f) + g) + h)

you calculate:

  (((a + b) + (c + d)) + ((e + f) + (g + h)))

Obviously this requires more space than the naive sum, but not as much as
you might at first expect: you only need to hold log(n) intermediates
values at any time.



Yep, I did mention in my post that the outer loop does not *have* to
be O(N), if you can parallelize it.  Apart from reducing
intermediates, the divide-and-conquer method does not reduce overall
computation time unless you have multiple processors, correct?



With a single thread of execution it can reduce the time for large integers and 
custom numerical types, with n the number of final bits, from O(n^2) to O(n log n).


I don't think the parallelism here is very relevant for Python.

From a more practical point of view, the sum efficiency could be improved by 
doing the first addition using '+' and the rest using '+=', without changing the 
behavior.



Cheers & hth.,

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


Re: sum for sequences?

2010-03-28 Thread Steve Howell
On Mar 28, 9:56 am, "Alf P. Steinbach"  wrote:
> * Steve Howell:
>> (talking about summing a list of lists)
>
>  From a more practical point of view, the sum efficiency could be improved by
> doing the first addition using '+' and the rest using '+=', without changing 
> the
> behavior.

I like that approach, because you don't have to assume that the start
object is clonable, although perhaps you need to make that assumption
anyway for the case where the list is empty.

Here is code that might shed light on Alf's suggested approach:

import timeit
M = 10
N = 8000

def in_place(
start = [],
sublists = ([[None] * M]) * N
):
# only macro-optimized
i = 0
for sublist in sublists:
if i == 0:
   accum = start + sublist
   i += 1
else:
accum.extend(sublist)
if i == 0:
return 'whatever' # semantics here?
return accum

def with_intermediates(
start = [],
sublists = ([[None] * M]) * N
):
accum = start
for sublist in sublists:
accum = accum + sublist
return accum

t1 = timeit.timeit('in_place()', 'from __main__ import in_place',
number=10)
t2 = timeit.timeit('with_intermediates()', 'from __main__ import
with_intermediates', number=10)
print M, N, t1, t2, int(t2 / t1)

For N=100, you get a significant speedup (x84):

 10 1000 0.00102496147156 0.0867249965668 84

More data:

 10 1000 0.00102496147156 0.0867249965668 84
 10 2000 0.00211381912231 0.172616004944 81
 10 4000 0.00491786003113 0.561800956726 114
 10 8000 0.0706541538239 19.9019489288 281
 10 16000 0.0161759853363 9.64171791077 596
 10 32000 0.0351569652557 43.98346591 1251

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


Re: sum for sequences?

2010-03-28 Thread Patrick Maupin
On Mar 28, 11:56 am, "Alf P. Steinbach"  wrote:
>  From a more practical point of view, the sum efficiency could be improved by
> doing the first addition using '+' and the rest using '+=', without changing 
> the
> behavior.

Mod parent up :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sum for sequences?

2010-03-28 Thread Steve Howell
On Mar 28, 10:21 am, Steve Howell  wrote:
>     import timeit
>     M = 10
>     N = 8000
>
>     def in_place(
>         start = [],
>         sublists = ([[None] * M]) * N
>         ):
>         # only macro-optimized
>         i = 0
>         for sublist in sublists:
>             if i == 0:
>                accum = start + sublist
>                i += 1
>             else:
>                 accum.extend(sublist)

FYI I later obtained similar results with the more general:
  accum += sublist

>         if i == 0:
>             return 'whatever' # semantics here?
>         return accum
>
>     def with_intermediates(
>         start = [],
>         sublists = ([[None] * M]) * N
>         ):
>         accum = start
>         for sublist in sublists:
>             accum = accum + sublist
>         return accum
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sum for sequences?

2010-03-28 Thread Patrick Maupin
On Mar 28, 12:34 pm, Steve Howell  wrote:
> FYI I later obtained similar results with the more general:
>                   accum += sublist

Yeah, but you still have to create an object of the correct type for
accum.  And for summing small lists, that will actually increase the
runtime.  (Worst case, a list of a single item: you have to create the
accum object based on the type of the start value, then do two += into
it, for the start value and the first item in the list, vs just doing
a single + which automatically creates an object.)

Personally, I think the most general approach, if sum were open to
enhancements, would be to automatically apply Alf's suggestion of "+"
on summing the first item to the start value, and "+=" on subsequent
items.  Also, you *could* add a parameter to sum(), for example,
default "partialsums=False" that would allow the use of partial sums
in those cases where that might give better behavior (such as floats
and tuples).

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


Re: sum for sequences?

2010-03-28 Thread Steve Howell
On Mar 28, 11:16 am, Patrick Maupin  wrote:
> On Mar 28, 12:34 pm, Steve Howell  wrote:
>
> > FYI I later obtained similar results with the more general:
> >                   accum += sublist
>
> Yeah, but you still have to create an object of the correct type for
> accum.  

I think you overlooked the surrounding code.

Here is the code again:

def in_place(
start = [],
sublists = ([[None] * M]) * N
):
# only macro-optimized
i = 0
for sublist in sublists:
if i == 0:
   accum = start + sublist
   i += 1
else:
accum += sublist
if i == 0:
return 'whatever' # semantics here?
return accum

No need to infer the type.

> And for summing small lists, that will actually increase the
> runtime.  (Worst case, a list of a single item: you have to create the
> accum object based on the type of the start value, then do two += into
> it, for the start value and the first item in the list, vs just doing
> a single + which automatically creates an object.)
>

For small lists, the performance of any sane implementation would
probably be so fast as to be negligible, unless you are in a really
tight loop.  If you are in a tight loop, then your use case probably
eventually sums large lists.  Even if it doesn't, the slowdown is just
a constant.

For M=5, I get these results on my machine:

M N t1 t2 (t2/t1)
5 1 3.50475311279e-05 3.2901763916e-05 0.938775510204
5 2 2.00271606445e-05 1.59740447998e-05 0.797619047619
5 4 6.79492950439e-05 6.31809234619e-05 0.929824561404
5 8 0.000124931335449 0.000126123428345 1.00954198473
5 64 0.000530958175659 0.00226187705994 4.25999101931
5 1024 0.00262904167175 0.27246594429 103.636981953

t1 = time with add only first element
t2 = time with add all elements

Very small penalty for small lists, very large gain for large lists.

> Personally, I think the most general approach, if sum were open to
> enhancements, would be to automatically apply Alf's suggestion of "+"
> on summing the first item to the start value, and "+=" on subsequent
> items.  

See above.  That's the approach I would use as well.

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


Re: Simple Traits Questions

2010-03-28 Thread Robert Kern

On 2010-03-28 08:46 , Ethan Furman wrote:

Robert Kern wrote:

On 2010-03-27 08:19 , Ethan Furman wrote:


Okay, different post for my actual questions. :)

On the PyPI page for strait (http://pypi.python.org/pypi/strait/0.5.1)
it has the example of choosing which methods to keep in the composed
class:

class TOSWidget(BaseWidget):
__metaclass__ = include(Pack, Place, Grid)
info = Pack.info.im_func
config = Pack.config.im_func
configure = Pack.configure.im_func
slaves = Pack.slaves.im_func
forget = Pack.forget.im_func
propagate = Pack.propagate.im_func

My question is:

Why use

info = Pack.info.im_func

instead of

info = Pack.info

?



Pack.info is an unbound method object attached to the Pack class, not
a function object. It has some extra semantics on top of functions and
is tied to the Pack class. The .im_func attribute gets the actual
function object underneath. When defining the TOSWidget class, the
objects defined in the suite under the class: statement need to be
actual functions in order to be turned into unbound methods attached
to the TOSWidget class.


Ah, thank you.

In Python 3, though, would the Pack.info form be correct?


Seems so:

Python 3.1 (r31:73578, Jun 27 2009, 21:49:46)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> class Pack():
...   def info(self, x):
... pass
...
>>> Pack.info


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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


Re: Have you embraced Python 3.x yet?

2010-03-28 Thread James Matthews
I am still on py 2.6 and since my code is heavy model dependent. I am bound
to the most critical ones. Although I would really like if someone could
backport some new stuff done with the GIL on 3.2 (they had a nice talk about
it at PyCon)

On Fri, Mar 26, 2010 at 5:33 PM, geremy condra  wrote:

> On Fri, Mar 26, 2010 at 9:23 AM, Harishankar 
> wrote:
> > Have you people embraced Python 3.x or still with 2.5 or 2.6?
> >
> > I personally want to switch over but not too sure how many people are
> > using 3.x as opposed to 2 so I want to keep my programs compatible for
> > the majority.
> >
> > -- Hari
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
>
> Yes- I write new code in 3.x and backport it PRN.
>
> Geremy Condra
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://www.goldwatches.com

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


ANN: Pyasm version 0.3

2010-03-28 Thread Grant Olson
Pyasm is a full-featured dynamic assembler written entirely in Python.
By dynamic, I mean that it can be used to generate and execute machine
code in python at runtime without requiring the generation of object
files and linkage. It essentially allow 'inline' assembly in python
modules on x86 platforms.

In addition, pyasm can generate COFF format object files, which may be
of interest to anyone writing a compiler in python.

More details and downloads are available at:

http://www.grant-olson.net/python/pyasm

The 0.3 release is long overdue.  It includes:

+ A binary installer for python 2.6.  The previous binary installer was
python 2.4.

+ Automatic mapping of python structure values in the assembler.  For
Example, assuming EAX is a pointer to a string, MOV
[EAX+PyString_ob_sval],0x42424242 will change the first four letters of
the string to B's

+ The assembler now supports implicit string creation: PUSH 'foo\n\0'

+ The ability to build and test with the mingw toolset on windows.  This
previously required an MSVC toolset.  Thanks to Markus Läll for sorting
this out.

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


Re: map, index

2010-03-28 Thread Paul Rubin
Luis Quesada  writes:
>> [ id*v for id,v in enumerate(L) ]
> Cool! Thanks!

If you really want to write that in pointfree style (untested):

   import itertools, operator
   ...
   itertools.starmap(operator.mul, enumerate(L))

For your other question, you could probably do something ugly
with ifilter, but it's not worth it.  

For the style of programming you're interested in, you should read the
docs for the itertools module.  Python culture in general tends to
not be that fond of heavy use of HOF's, since it's very easy to make
mistakes with its iterator protocol and with its dynamic type system.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sum for sequences?

2010-03-28 Thread Paul Rubin
Steve Howell  writes:
> The documentation is pretty clear on the intention that sum() is
> intended for numbers: ...

I've never been big on the idea of duck-typing addition.  Who would have
thought that (1,2,3)+(4.5.6) was something other than the vector sum?

I think itertools.chain more directly expresses what the OP was trying
to do, and is preferable for readability, independently of these
performance questions.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Psycopg2 - Interface Error : Connection already closed

2010-03-28 Thread Philip Semanchuk


On Mar 27, 2010, at 5:14 PM, knobbyknees wrote:


I'm not sure if this is the right group, but I'm hoping it is...

Basically, I'm trying to use pgloader, which depends on python and
psycopg2.  After banging my head against a wall, I found this:

Found this:
http://www.mail-archive.com/sqlalch...@googlegroups.com/msg13209.html

Although, the suggestion didn't work for me at all...

Running this command:
/usr/bin/pgloader -c /var/mybin/pgconfs/fr.conf

Yields this in the pgloader.log (with the process just hanging)

more /tmp/pgloader.log
27-03-2010 12:22:53 pgloader INFO Logger initialized
27-03-2010 12:22:53 pgloader INFO Reformat path is ['/usr/
share/python-support/pgloader/reformat']
27-03-2010 12:22:53 pgloader INFO Will consider following
sections:
27-03-2010 12:22:53 pgloader INFO   fixed
27-03-2010 12:22:54 fixedINFO fixed processing
27-03-2010 12:22:54 pgloader INFO All threads are started,
wait for them to terminate
27-03-2010 12:22:57 fixedERRORconnection already closed
27-03-2010 12:22:57 fixedINFO closing current database
connection

[pgsql]
host  = localhost
port  = 5432
base  = frdb
user  = username
pass  = password


[fixed]
table = fr
format= fixed
filename  = /var/www/fr.txt
...


This is what I see for the traceback:
Traceback (most recent call last):
 File "/usr/lib/python2.6/threading.py", line 525, in
__bootstrap_inner
   self.run()
 File "/usr/lib/pymodules/python2.6/pgloader/pgloader.py", line 847,
in run
   self.terminate()
 File "/usr/lib/pymodules/python2.6/pgloader/pgloader.py", line 874,
in terminate
   self.db.close()
 File "/usr/lib/pymodules/python2.6/pgloader/db.py", line 103, in
close
   self.dbconn.close()


I'm at a total loss here  Can anyone please help me out?


Hi knobbyknees,
I can't help you with this problem, but the folks on the psycopg2  
mailing list are probably a much better crowd to ask:

http://lists.initd.org/mailman/listinfo/psycopg


Good luck
Philip
--
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Traits Questions

2010-03-28 Thread Terry Reedy

On 3/28/2010 9:46 AM, Ethan Furman wrote:

Robert Kern wrote:

On 2010-03-27 08:19 , Ethan Furman wrote:


Okay, different post for my actual questions. :)

On the PyPI page for strait (http://pypi.python.org/pypi/strait/0.5.1)
it has the example of choosing which methods to keep in the composed
class:

class TOSWidget(BaseWidget):
__metaclass__ = include(Pack, Place, Grid)
info = Pack.info.im_func
config = Pack.config.im_func
configure = Pack.configure.im_func
slaves = Pack.slaves.im_func
forget = Pack.forget.im_func
propagate = Pack.propagate.im_func

My question is:

Why use

info = Pack.info.im_func

instead of

info = Pack.info

?



Pack.info is an unbound method object attached to the Pack class, not
a function object. It has some extra semantics on top of functions and
is tied to the Pack class. The .im_func attribute gets the actual
function object underneath. When defining the TOSWidget class, the
objects defined in the suite under the class: statement need to be
actual functions in order to be turned into unbound methods attached
to the TOSWidget class.


Ah, thank you.

In Python 3, though, would the Pack.info form be correct?


Yes. One of the simplifications of Py3.

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


OT: Tech Adviser Wanted by Unusual Social Venture Startup AND WEBEX QUESTION

2010-03-28 Thread Fabian Hernandez
-- Forwarded message --
From: G.Lowell Krane 
Date: 2010/3/27
Subject: Fwd: [Off Topic] Tech Adviser Wanted by Unusual Social Venture
Startup AND WEBEX QUESTION
To: Daniel Arbelaez 
Cc: arpunk , Fabian Hernandez 


Here is the ad i am trying to get Python-list to post ASAP--this weekend.

Also, in case one of your best applications is not public, and you want to
demonstrate it, do you prefer webex or what do you prefer?
--gary

-- Forwarded message --
From: G.Lowell Krane 
Date: Fri, Mar 26, 2010 at 4:26 PM
Subject: [Off Topic] Tech Adviser Wanted by Unusual Social Venture Startup
To: python-list@python.org


TECH ADVISOR (1-3 hrs/wk) WANTED FOR UNUSUAL SOCIAL VENTURE STARTUP


This position is for an unusual well advanced (though not yet in beta)
Social Venture Internet Startup that has hopefully figured out a way  through
an unusually  robust web application to help the 95% of unhappy couples in
the Western Hemisphere who cannot afford or will not trust a marriage
therapist,  to save, ensure, deepen their relationships (about 60MM
couples!). The monetization model is initially subscriber (very low fee that
mkt research (harris poll) has shown the majority of these in USA, at least
would like to use this for about $20/mo for at least 3 mo or longer as long
as they felt it was helping at least a little.) Our startup, eCoupleCoach
/ParejasContentas, would in fact be the pioneer of this blue ocean market
using a conceptual advance, and employing a social media as well as "tapping
the wisdom of the best experts" model.


Our urgent need now is for someone who is a senior level
developer/programmer to be able to vet three or four of the best  web
application teams we have finally found, or at least the one python team we
found (in Bogota, where I, the ceo/founder/head research psychologist, will
be working with them daily to ensure  maximum efficiency).**

*BTW, anyone who has gone through a tough divorce (or whose parents divorced
at a tender age, will probably find this enormously fascinating and
gratifying—an opportunity to turn your lemons into lemonade.*

Besides the python freelance team ( team, we also have a .net  freelance
team, and  php company . We might identify a 4th soon.  But the priority now
is to vet the python team—one lead developer who has been doing python on
and off (part and fulltime )for several years (but collapsed, 3 years), and
the other developer, about 1 year. The third member of their team is more of
a designer, doing css and html.

After this vetting, we ideally hope, if you are excited about our potential
and yours with us, that you will want to stay on  up to two hours a week (of
course the more you can devote the better if you are interested in any other
challenges) to at least  QA the code quality and make sure it is being
dumped at least weekly.

WHAT WE HAVE GOING FOR US: A lot. Once we hear from you, we will send
detailed backgrounders.

COMPENSATION: would be negotiable and this could also lead to a highly
responsible high up position once we are funded.

TO APPLY: PLEASE email me at ecoupleco...@gmail.com to make initial contact,
and send us your resume. After this we will
Send you detailed backgrounders on who we are and what we have going for us.

IN YOUR SIGNATURE (so easy to find): Please also indicate your skype contact
info, for follow up phone conversation, unless you prefer chat, in which
case your chat contact info (preferably google), since I am in Colombia now
and will be till the beta is done, though my partner and VP of Product
Development/Project Manager is in NYC.






Gary Krane PhD, CEO/founder Relationship Technologies (ParejasContentas y
eCoupleCoach)
"Tapping the wisdom of the best experts and the wisest couples (TM)," and
"Making Honesty easier than ever before."
Medellin and Bogota: 300 415 5298
Skype: garykrane

"The greatness of a human is to be measured exactly by the degree to which
he has helped his/her fellow human."-Gandhi
"The best things in life are not things" (anon)




-- 
Attentamente,
Gary Krane PhD, CEO/founder Relationship Technologies (ParejasContentas y
eCoupleCoach)
"Tapping the wisdom of the best experts and the wisest couples (TM)," and
"Making Honesty easier than ever before."
Medellin: 300 415 5298
Skype: garykrane

"Un ser humano se convierte en una gran exactitud en la medida en la que él
trabaja para el bienestar de sus compañeros " - Mahatma Gandhi
"The greatness of a human is to be measured exactly by the degree to which
he has helped his/her fellow human."-Gandhi
"The best things in life are not things" (anon)




-- 
Fabian Hernandez Nieto
http://www.sidesoftware.net
Linux User # 485518
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Off Topic] Tech Adviser Wanted by Unusual Social Venture Startup AND WEBEX QUESTION

2010-03-28 Thread Fabian Hernandez
2010/3/27 G.Lowell Krane 

> Here is the ad i am trying to get Python-list to post ASAP--this weekend.
>
> Also, in case one of your best applications is not public, and you want to
> demonstrate it, do you prefer webex or what do you prefer?
> --gary
>
> -- Forwarded message --
> From: G.Lowell Krane 
> Date: Fri, Mar 26, 2010 at 4:26 PM
> Subject: [Off Topic] Tech Adviser Wanted by Unusual Social Venture Startup
> To: python-list@python.org
>
>
> TECH ADVISOR (1-3 hrs/wk) WANTED FOR UNUSUAL SOCIAL VENTURE STARTUP
>
>
> This position is for an unusual well advanced (though not yet in beta)
> Social Venture Internet Startup that has hopefully figured out a way  through
> an unusually  robust web application to help the 95% of unhappy couples in
> the Western Hemisphere who cannot afford or will not trust a marriage
> therapist,  to save, ensure, deepen their relationships (about 60MM
> couples!). The monetization model is initially subscriber (very low fee that
> mkt research (harris poll) has shown the majority of these in USA, at least
> would like to use this for about $20/mo for at least 3 mo or longer as long
> as they felt it was helping at least a little.) Our startup, eCoupleCoach
> /ParejasContentas, would in fact be the pioneer of this blue ocean market
> using a conceptual advance, and employing a social media as well as "tapping
> the wisdom of the best experts" model.
>
>
> Our urgent need now is for someone who is a senior level
> developer/programmer to be able to vet three or four of the best  web
> application teams we have finally found, or at least the one python team we
> found (in Bogota, where I, the ceo/founder/head research psychologist, will
> be working with them daily to ensure  maximum efficiency).**
>
> *BTW, anyone who has gone through a tough divorce (or whose parents
> divorced at a tender age, will probably find this enormously fascinating and
> gratifying—an opportunity to turn your lemons into lemonade.*
>
> Besides the python freelance team ( team, we also have a .net  freelance
> team, and  php company . We might identify a 4th soon.  But the priority
> now is to vet the python team—one lead developer who has been doing python
> on and off (part and fulltime )for several years (but collapsed, 3 years),
> and the other developer, about 1 year. The third member of their team is
> more of a designer, doing css and html.
>
> After this vetting, we ideally hope, if you are excited about our potential
> and yours with us, that you will want to stay on  up to two hours a week (of
> course the more you can devote the better if you are interested in any other
> challenges) to at least  QA the code quality and make sure it is being
> dumped at least weekly.
>
> WHAT WE HAVE GOING FOR US: A lot. Once we hear from you, we will send
> detailed backgrounders.
>
> COMPENSATION: would be negotiable and this could also lead to a highly
> responsible high up position once we are funded.
>
> TO APPLY: PLEASE email me at ecoupleco...@gmail.com to make initial
> contact, and send us your resume. After this we will
> Send you detailed backgrounders on who we are and what we have going for
> us.
>
> IN YOUR SIGNATURE (so easy to find): Please also indicate your skype
> contact info, for follow up phone conversation, unless you prefer chat, in
> which case your chat contact info (preferably google), since I am in
> Colombia now and will be till the beta is done, though my partner and VP of
> Product Development/Project Manager is in NYC.
>
>
>
>
>
>
> Gary Krane PhD, CEO/founder Relationship Technologies (ParejasContentas y
> eCoupleCoach)
> "Tapping the wisdom of the best experts and the wisest couples (TM)," and
> "Making Honesty easier than ever before."
> Medellin and Bogota: 300 415 5298
> Skype: garykrane
>
> "The greatness of a human is to be measured exactly by the degree to which
> he has helped his/her fellow human."-Gandhi
> "The best things in life are not things" (anon)
>
>
>
>
> --
> Attentamente,
> Gary Krane PhD, CEO/founder Relationship Technologies (ParejasContentas y
> eCoupleCoach)
> "Tapping the wisdom of the best experts and the wisest couples (TM)," and
> "Making Honesty easier than ever before."
> Medellin: 300 415 5298
> Skype: garykrane
>
> "Un ser humano se convierte en una gran exactitud en la medida en la que él
> trabaja para el bienestar de sus compañeros " - Mahatma Gandhi
> "The greatness of a human is to be measured exactly by the degree to which
> he has helped his/her fellow human."-Gandhi
> "The best things in life are not things" (anon)
>
>


-- 
Fabian Hernandez Nieto
http://www.sidesoftware.net
Linux User # 485518
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: map, index

2010-03-28 Thread Luis Quesada

Paul Rubin wrote:

Luis Quesada  writes:

[ id*v for id,v in enumerate(L) ]

Cool! Thanks!


If you really want to write that in pointfree style (untested):

   import itertools, operator
   ...
   itertools.starmap(operator.mul, enumerate(L))

For your other question, you could probably do something ugly
with ifilter, but it's not worth it.  


For the style of programming you're interested in, you should read the
docs for the itertools module.  Python culture in general tends to
not be that fond of heavy use of HOF's, since it's very easy to make
mistakes with its iterator protocol and with its dynamic type system.

Thanks a lot for the pointer.
Python is rather cool indeed.
Cheers,
Luis
--
http://mail.python.org/mailman/listinfo/python-list


RE: Re: Super() function

2010-03-28 Thread Delaney, Timothy (Tim)
> Gabriel Genellina wrote:
>> Alan Harris-Reid  escribió:
>>
>>> Using Python 3.1, I sometimes use the super() function to call the 
>>> equivalent method from a parent class, for example
>>>
>>> def mymethod(self):
>>> super().mymethod()
>>> some more code...
>>>
>>> Is there any way of writing the code so that the super() call is 
>>> generic and automatically recognises the name of the current method 
>>> (ie. something like super().thismethod()) or do I always have to 
>>> repeat the method name after super()?
>>
>> This recipe does what you want:
>> http://code.activestate.com/recipes/286195-selfsuper/
>> (but requires a bit of black magic...)
>>
> Hi Gabriel - thanks for the reply.
>
> Goodness me - that's a mighty complicated recipe for what I want to achieve!
> I think I'll stick with repeating the method name - it's a small price to pay.

I wrote that recipe back before Python 3.x supported super() without parameters,
and near equivalent functionality was part of the new super PEP as an option.
However, Guido decided to go with the much simpler super().attr with no 
shortcutting.

If you think the pure-python version of the recipe is complicated, you should 
have
a look at the performance-optimised Pyrex version ;)

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


Re: sum for sequences?

2010-03-28 Thread Steven D'Aprano
On Sun, 28 Mar 2010 13:49:32 -0700, Paul Rubin wrote:

> Steve Howell  writes:
>> The documentation is pretty clear on the intention that sum() is
>> intended for numbers: ...
> 
> I've never been big on the idea of duck-typing addition.  Who would have
> thought that (1,2,3)+(4.5.6) was something other than the vector sum?

But your arguments are tuples, not vectors.

There are languages which do treat arithmetic operations on vectors as 
vector operations, as do (e.g.) H-P scientific calculators. That's a fine 
design choice, and it works for languages where the emphasis is on 
scientific calculations. But Python is a more generalist language, so in 
my mind it is more appropriate to treat lists as generic lists, and not 
numeric vectors:

[1, 2, 3] + [4, "a"] => [1, 2, 3, 4, "a"]

just as

"123" + "4a" => "1234a"



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


pythoncom.CoInitialize() not recognised in Eclipse

2010-03-28 Thread KB
Hi there,

I have in the past used PythonWin to write python for COM, and
switched to Eclipse.

I am getting an error from the IDE saying it does not recognise
CoInitialize():


import pythoncom

pythoncom.CoInitialize()
pythoncom.CoUninitialize()


(red X next to the two bottom lines saying: "Undefined variable from
import: CoInitialize")

If I open a PyDev/Python Console window in Eclipse, I can type the
above, no errors, no problem.

I tried removing my Python Interpreter and re-adding/re-building but
no change.

python 2.5.2
eclipse 3.5.1
pydev 1.5.0

Thanks!

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


Re: Have you embraced Python 3.x yet?

2010-03-28 Thread Ray Allen
  In our company, we still use python-2.5.4, and will be updated to
python-2.5.5. I hope we can go to 2.6.x or 3.x, but I'm not sure when.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sum for sequences?

2010-03-28 Thread Steven D'Aprano
On Sun, 28 Mar 2010 18:56:26 +0200, Alf P. Steinbach wrote:

> From a more practical point of view, the sum efficiency could be
> improved by doing the first addition using '+' and the rest using '+=',
> without changing the behavior.

But that would change the behaviour. The __iadd__ method is not the same 
as the __add__ method, and you can't guarantee that they will behave the 
same -- or even similarly.

And what about tuples? And subclasses of list/tuples? How many different 
types need to be optimized?

In practical terms, does anyone actually ever use sum on more than a 
handful of lists? I don't believe this is more than a hypothetical 
problem.

The primary use case for sum is adding numbers when floating point 
accuracy is not critical. If you need float accuracy, use math.fsum. If 
you need to add more than a handful of small lists, don't use sum: just 
calling extend in a loop is probably fast enough, or use itertools.chain. 
Trying to turn sum into an all-singing all-dancing function optimised for 
an ever-increasing number of objects is a fool's errand. The 
implementation of sum in C is already complex enough: 95 lines, excluding 
comments, blanks and braces, for something which is a lightweight 
function with very simple semantics.

But if anyone wants to submit a patch to the bug tracker, go right ahead. 
Without a patch though, I'd say that Python-Dev will consider this a non-
issue.



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


Re: pythoncom.CoInitialize() not recognised in Eclipse

2010-03-28 Thread Jason Scheirer
On Mar 28, 7:14 pm, KB  wrote:
> Hi there,
>
> I have in the past used PythonWin to write python for COM, and
> switched to Eclipse.
>
> I am getting an error from the IDE saying it does not recognise
> CoInitialize():
>
> 
> import pythoncom
>
> pythoncom.CoInitialize()
> pythoncom.CoUninitialize()
> 
>
> (red X next to the two bottom lines saying: "Undefined variable from
> import: CoInitialize")
>
> If I open a PyDev/Python Console window in Eclipse, I can type the
> above, no errors, no problem.
>
> I tried removing my Python Interpreter and re-adding/re-building but
> no change.
>
> python 2.5.2
> eclipse 3.5.1
> pydev 1.5.0
>
> Thanks!

PyDev is probably only looking at functions/classes defined in Python
source files and not ones defined in C extensions.

To confirm, try typing this in the window:

import _ctypes
_ctypes._Pointer()

If it says that _ctypes._Pointer doesn't exist, then that's obviously
the problem.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythoncom.CoInitialize() not recognised in Eclipse

2010-03-28 Thread Dieter Verfaillie

Quoting KB :

I am getting an error from the IDE saying it does not recognise
CoInitialize():


import pythoncom

pythoncom.CoInitialize()
pythoncom.CoUninitialize()



It works out of the box with PyDev 1.5.5.2010030420 on Eclipse 3.5.2  
on Windows XP. If nothing seems to work for you, you could try adding  
pythoncom to the

"Forced Builtins" tab of your Python interpreter configuration to see if it
helps (restart eclipse after you've done that, sometimes changes to  
the symbols

database don't get picked up without restarting eclipse...)

mvg,
Dieter


This message was sent using IMP, the Internet Messaging Program.

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


How to verify a signature using SHA1WithRSA with python

2010-03-28 Thread Gao
I have a public key, and I want to write a method that verify a string 
which is a signature signed by this public key's private key. And is 
M2Crypto I can't find algorithm named "SHA1WithRSA" or so . Could anyone 
help me?

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