Re: Generator expressions vs. comprehensions

2010-05-25 Thread Peter Otten
Michele Simionato wrote:

> On May 25, 12:47 am, Carl Banks  wrote:
>> The situation here is known.  It can't be corrected, even in Python 3,
>> without modifying iterator protocol to tie StopIteration to a specific
>> iterator.  This is possible and might be worth it to avoid hard-to-
>> diagnose bugs but it would complicate iterator protocol, which becomes
>> less useful as it becomes more complex.
> 
> The situation here is a known and could be corrected by changing the
> meaning of list comprehension,
> for instance by having [x for x in iterable] to be an alias for list(x
> for x in iterable). In such a way the StopIteration exception would be
> always swallowed and there would be consistency with generator
> expressions (by construction). However, the list comprehension would
> become non-equivalent to the corresponding for-loop with an .append,
> so somebody would be un happy anyway :-/

But the list comprehension is already non-equivalent to the for loop as the 
loop variable isn't leaked anymore. We do have three similar constructs with 
subtle differences. 

I think not turning the list-comp into syntactic sugar for list(genexp) in 
py3 is a missed opportunity.

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


Re: Question on Python Function

2010-05-25 Thread Peter Otten
Kushal Kumaran wrote:

> On Tue, May 25, 2010 at 3:38 AM, joy99  wrote:
>> 
>>
>> Dear Vlastimir,
>>
>> As pointed out by Alister, I can print the values of function1 and
>> function2 with the help of another function3, but my target is to call
>> the "add" value of function1 and "mult" value of function2 in a third
>> function or the values and parameters of the third function in fourth
>> function. While calling, I am looking not only to print, but to use
>> them or manipulate them.
>>
>> I hope I am bit clear now.
>>
> 
> If you need to use the values in another function, you need a way to
> let that function get its hands on the values.  Your function1 and
> function2 should return the values they compute instead of printing
> them out.

For example:

 >>> def add(x, y):
... return x + y
...
>>> def mul(x, y):
... return x * y
...
>>> def sum_of_squares(x, y):
... return add(mul(x, x), mul(y, y))
...
>>> sum_of_squares(3, 4)
25

OP: If that addresses your question I suggest that you work through some 
introductory text about python. The python wiki has a few suggestions, see

http://wiki.python.org/moin/BeginnersGuide

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


Re: Generator expressions vs. comprehensions

2010-05-25 Thread Michele Simionato
On May 25, 9:08 am, Peter Otten <__pete...@web.de> wrote:
> But the list comprehension is already non-equivalent to the for loop as the
> loop variable isn't leaked anymore. We do have three similar constructs with
> subtle differences.
>
> I think not turning the list-comp into syntactic sugar for list(genexp) in
> py3 is a missed opportunity.

Actually I do agree with the feeling, and this is not the only missed
opportunity in Python 3 :-/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function that counts...

2010-05-25 Thread Jean-Michel Pichavant

superpollo wrote:

Jean-Michel Pichavant ha scritto:

Jerry Hill wrote:

On Wed, May 19, 2010 at 3:58 PM, superpollo  wrote:
 
... how many positive integers less than n have digits that sum up 
to m:


...
 

any suggestion for pythonizin' it?



This is how I would do it:

def prttn(m, n):
"""How many positive integers less than n have digits that sum 
up to m"""

total = 0
for testval in range(n):
sumofdigits = sum(int(char) for char in str(testval))
if sumofdigits == m:
total += 1
return total

I added a docstring to the function, saying what it does, and what the
arguments are supposed to represent.  I also moved the
convert-to-string-and-sum-the-digits logic into a single generator
expression that's passed to the builtin sum function.  Oh, and I tried
to use slightly more expressive variable names.

  

my favorite solutio nso far.

@ OP

What means prttn ? 


i already answered this downthreads...

something ... I don't find the word, something like un-intuitive. 
Sounds like homework.


it is not.

My apologies then, for both statements.
I still don't see "how many positive integers less than n have digits 
that sum up to m" makes it a "partition" though if that what prttn 
means. Surely because I miss the context.


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


asyncore loop and cmdloop problem

2010-05-25 Thread kak...@gmail.com
Hi to all,
i'm creating a command line application using asyncore and cmd. At

if __name__ == '__main__':
import socket

args = sys.argv[1:]
if not args:
print "Usage: %s querystring" % sys.argv[0]
sys.exit(0)


address = ('localhost', 0) # let the kernel give us a port
server = EchoServer(address)
ip, port = server.address # find out what port we were given

asyncore.loop()
CmdClass().cmdloop()

what i want is that the above commands asyncore.loop() and
CmdClass().cmdloop()
running at the same time. Meaning that while the application is in cmd
mode
with the cmdloop(), it is still able to listen for incoming messages?
What should i do?

thanks in advance
A.K.
-- 
http://mail.python.org/mailman/listinfo/python-list


Help regarding XML file manipulation

2010-05-25 Thread Salil GK
Hello

  I need to make a quick prototype to process some xml file. I found
xml.dom.minidom much handy and I can get information from the xml file. But
I need to update a filed in the xml file and save the file. I couldn't find
a way to do that. Could some one please help me on this.

Basically this is what I want to do



 
  Hari
  102010
  201010

  Rama
  102010
  201010

 


Here I want to read the Engineer information and then change the NextLeave
information to a new value and save to the same file. How do we do this -
can some one please help me with some sample code for the same.

Thanks
~S
-- 
http://mail.python.org/mailman/listinfo/python-list


how to run brill tagger on urdu corpus?

2010-05-25 Thread fari
 I like to run brill demo function with urdu pos tagged i have urdu
corpus reader and a POS tagged file can you help me.

1) how and where i need to define templates for urdu . Is template dat
are given with nltk(brill) are compatible to run with urdu.
2) If i want to run brill demo function on urdu tag what should i do ?
  waiting for reply plz.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: asyncore loop and cmdloop problem

2010-05-25 Thread Michele Simionato
On May 25, 10:42 am, "kak...@gmail.com"  wrote:
> Hi to all,
> i'm creating a command line application using asyncore and cmd. At
>
> if __name__ == '__main__':
>     import socket
>
>     args = sys.argv[1:]
>     if not args:
>         print "Usage: %s querystring" % sys.argv[0]
>         sys.exit(0)
>
>     address = ('localhost', 0) # let the kernel give us a port
>     server = EchoServer(address)
>     ip, port = server.address # find out what port we were given
>
>     asyncore.loop()
>     CmdClass().cmdloop()
>
> what i want is that the above commands asyncore.loop() and
> CmdClass().cmdloop()
> running at the same time. Meaning that while the application is in cmd
> mode
> with the cmdloop(), it is still able to listen for incoming messages?
> What should i do?
>
> thanks in advance
> A.K.

cmd.Cmd is blocking, so the only way it to run the cmdloop in a
separated thread. Once for fun
I rewrote the cmd module to be non-blocking but if you want to stick
with the standard library you need to use a thread.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reading data from a Microsoft Access 2003 database

2010-05-25 Thread Jimoid
This is perfect if the python ODBC driver can read the .mdb  without
the need for it to be running elsewhere.

Thanks all for your help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help regarding XML file manipulation

2010-05-25 Thread Shashank Singh
On Tue, May 25, 2010 at 2:24 PM, Salil GK  wrote:

> Hello
>
>   I need to make a quick prototype to process some xml file. I found
> xml.dom.minidom much handy and I can get information from the xml file. But
> I need to update a filed in the xml file and save the file. I couldn't find
> a way to do that. Could some one please help me on this.
>
> Basically this is what I want to do
>
> 
> 
>  
>   Hari
>   102010
>   201010
>
>   Rama
>   102010
>   201010
>
>  
> 
>
> Here I want to read the Engineer information and then change the NextLeave
> information to a new value and save to the same file. How do we do this -
> can some one please help me with some sample code for the same.
>

have a look at the xml.dom.minidom module.
You can access nodes by getElementsByTagName("Engineer")
Access value of the text node by node.nodeValue

To modify the xml, you will have to set the node value to the desired value
node.nodeValue = newValue

Note that to you will have to write the modified dom object back to the file
to save the changes, just setting the value of nodes will not automatically
do that.

HTH
-S

>
> Thanks
> ~S
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
Regards
Shashank Singh
Senior Undergraduate, Department of Computer Science and Engineering
Indian Institute of Technology Bombay
shashank.sunny.si...@gmail.com
http://www.cse.iitb.ac.in/~shashanksingh
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: asyncore loop and cmdloop problem

2010-05-25 Thread kak...@gmail.com
On May 25, 4:55 am, Michele Simionato 
wrote:
> On May 25, 10:42 am, "kak...@gmail.com"  wrote:
>
>
>
> > Hi to all,
> > i'm creating a command line application using asyncore and cmd. At
>
> > if __name__ == '__main__':
> >     import socket
>
> >     args = sys.argv[1:]
> >     if not args:
> >         print "Usage: %s querystring" % sys.argv[0]
> >         sys.exit(0)
>
> >     address = ('localhost', 0) # let the kernel give us a port
> >     server = EchoServer(address)
> >     ip, port = server.address # find out what port we were given
>
> >     asyncore.loop()
> >     CmdClass().cmdloop()
>
> > what i want is that the above commands asyncore.loop() and
> > CmdClass().cmdloop()
> > running at the same time. Meaning that while the application is in cmd
> > mode
> > with the cmdloop(), it is still able to listen for incoming messages?
> > What should i do?
>
> > thanks in advance
> > A.K.
>
> cmd.Cmd is blocking, so the only way it to run the cmdloop in a
> separated thread. Once for fun
> I rewrote the cmd module to be non-blocking but if you want to stick
> with the standard library you need to use a thread.

Thank you so much.
Is there a way that i can find that version of cmd?

Antonis

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


Re: asyncore loop and cmdloop problem

2010-05-25 Thread Giampaolo Rodolà
2010/5/25 Michele Simionato :
> On May 25, 10:42 am, "kak...@gmail.com"  wrote:
>> Hi to all,
>> i'm creating a command line application using asyncore and cmd. At
>>
>> if __name__ == '__main__':
>>     import socket
>>
>>     args = sys.argv[1:]
>>     if not args:
>>         print "Usage: %s querystring" % sys.argv[0]
>>         sys.exit(0)
>>
>>     address = ('localhost', 0) # let the kernel give us a port
>>     server = EchoServer(address)
>>     ip, port = server.address # find out what port we were given
>>
>>     asyncore.loop()
>>     CmdClass().cmdloop()
>>
>> what i want is that the above commands asyncore.loop() and
>> CmdClass().cmdloop()
>> running at the same time. Meaning that while the application is in cmd
>> mode
>> with the cmdloop(), it is still able to listen for incoming messages?
>> What should i do?
>>
>> thanks in advance
>> A.K.
>
> cmd.Cmd is blocking, so the only way it to run the cmdloop in a
> separated thread. Once for fun
> I rewrote the cmd module to be non-blocking but if you want to stick
> with the standard library you need to use a thread.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Too bad cmdloop() doesn't provide an argument to return immediately.
Why don't you submit this patch on the bug tracker?


--- Giampaolo
http://code.google.com/p/pyftpdlib
http://code.google.com/p/psutil
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: asyncore loop and cmdloop problem

2010-05-25 Thread Michele Simionato
On May 25, 12:03 pm, Giampaolo Rodolà  wrote:
> Too bad cmdloop() doesn't provide an argument to return immediately.
> Why don't you submit this patch on the bug tracker?
>
> --- Giampaolohttp://code.google.com/p/pyftpdlibhttp://code.google.com/p/psutil

Because it is not a bug, cmd was designed to be blocking. It would be
a feature request.
I wrote a cmd2 module a few years ago, which was intended as a
replacement for cmd with various
additional features (including the non blocking behavior). We are
using it in production, but I
have never published it (I intended to but, you know, a days has only
24 hours ;)
I should put together the code in a single file and publish it, but I
cannot guarantee if and when I will have the time to do so.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: asyncore loop and cmdloop problem

2010-05-25 Thread Giampaolo Rodolà
2010/5/25 Michele Simionato :
> On May 25, 12:03 pm, Giampaolo Rodolà  wrote:
>> Too bad cmdloop() doesn't provide an argument to return immediately.
>> Why don't you submit this patch on the bug tracker?
>>
>> --- 
>> Giampaolohttp://code.google.com/p/pyftpdlibhttp://code.google.com/p/psutil
>
> Because it is not a bug, cmd was designed to be blocking. It would be
> a feature request.

Sure, a feature request, but it would be nice to have anyway. =)
The OP question shown how this can be desirable in certain circumstances..

--- Giampaolo
http://code.google.com/p/pyftpdlib
http://code.google.com/p/psutil
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [wxPython-users] wxPython 2.8.11.0 release

2010-05-25 Thread Tom Browder
On Mon, May 24, 2010 at 18:38, Robin Dunn  wrote:
...
> The 2.8.11.0 release of wxPython is now available for download at
> http://wxpython.org/download.php. This release adds Python 2.7 builds,
> PySlices, new pubsub implementation, lots of updates to AGW, and lots
> of bugs fixed.  A summary of changes is listed below and also at
> http://wxpython.org/recentchanges.php.

Has the port to python 3 problem been solved in the development line,
or is help still looked for there?

See this Nov 19, 2009 msg:

http://groups.google.com/group/wxpython-users/browse_thread/thread/86f8b2513941d0f4/6d77c3d4ebd0e919?lnk=gst&q=python+3#6d77c3d4ebd0e919

Thanks,

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


Re: function that counts...

2010-05-25 Thread superpollo

Jean-Michel Pichavant ha scritto:

superpollo wrote:

Jean-Michel Pichavant ha scritto:

Jerry Hill wrote:

On Wed, May 19, 2010 at 3:58 PM, superpollo  wrote:
 
... how many positive integers less than n have digits that sum up 
to m:


...
 

any suggestion for pythonizin' it?



This is how I would do it:

def prttn(m, n):
"""How many positive integers less than n have digits that sum 
up to m"""

total = 0
for testval in range(n):
sumofdigits = sum(int(char) for char in str(testval))
if sumofdigits == m:
total += 1
return total

I added a docstring to the function, saying what it does, and what the
arguments are supposed to represent.  I also moved the
convert-to-string-and-sum-the-digits logic into a single generator
expression that's passed to the builtin sum function.  Oh, and I tried
to use slightly more expressive variable names.

  

my favorite solutio nso far.

@ OP

What means prttn ? 


i already answered this downthreads...

something ... I don't find the word, something like un-intuitive. 
Sounds like homework.


it is not.

My apologies then, for both statements.
I still don't see "how many positive integers less than n have digits 
that sum up to m" makes it a "partition" though if that what prttn 
means. Surely because I miss the context.


JM


ok, this is the mistery. it was inspired by a question on e.c.m.:

http://groups.google.it/group/es.ciencia.matematicas/msg/f8f09672bd8a052a

the first question is (somewhat) an instance of:

http://en.wikipedia.org/wiki/Partition_(number_theory)

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


Re: asyncore loop and cmdloop problem

2010-05-25 Thread kak...@gmail.com
On May 25, 6:48 am, Giampaolo Rodolà  wrote:
> 2010/5/25 Michele Simionato :
>
> > On May 25, 12:03 pm, Giampaolo Rodolà  wrote:
> >> Too bad cmdloop() doesn't provide an argument to return immediately.
> >> Why don't you submit this patch on the bug tracker?
>
> >> --- 
> >> Giampaolohttp://code.google.com/p/pyftpdlibhttp://code.google.com/p/psutil
>
> > Because it is not a bug, cmd was designed to be blocking. It would be
> > a feature request.
>
> Sure, a feature request, but it would be nice to have anyway. =)
> The OP question shown how this can be desirable in certain circumstances..
>
> --- Giampaolohttp://code.google.com/p/pyftpdlibhttp://code.google.com/p/psutil


Could you please provide me with a simple example how to do this with
threads.
I don't know where to put the cmdloop().
Please help, i' m so confused!
Thank you
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A Quick MySQL Question

2010-05-25 Thread Victor Subervi
On Tue, May 25, 2010 at 3:50 AM, Dennis Lee Bieber wrote:

> On Mon, 24 May 2010 13:37:58 -0400, Victor Subervi
>  declaimed the following in
>Parameterized queries process the parameters to ensure that they are
> safe for use in the SQL statement.
>
>In the case of the MySQLdb adapter (written to be compatible with
> pre-version 5 of MySQL) this means that the parameters are converted to
> a string representation (if not already a string), characters in the
> parameter that are significant to the MySQL dialect of SQL are safely
> escaped, AND the resulting string is WRAPPED in quote marks.
>
> k. That worked. Thanks!


>I suggest you study the SQL standard "like" comparison, and the use
> of wildcards with it. Consider a "card catalog" application and how one
> would formulate a query in which the author's last name is "Norton", and
> the title of the book contains the word "Witch" (the word could be
> anywhere within the title).
>

I understand how to do "like" queries and use wildcards. I didn't understand
what you were doing over there, something with %values% or some such. If you
care to pick up that thread, fine, otherwise, until the next time.

Thanks you as always, Dennis :)
beno
-- 
http://mail.python.org/mailman/listinfo/python-list


to prevent reveres engineering for Python

2010-05-25 Thread Sandy Ydnas

Agree, reveres engineering is crucial issuer  for programming language 
but every executable file can be cracked, for example  by using disassembler!!! 
 
For each weapon there is antiweapon, so
is it possible to prevent reveres engineering when customer have access to 
executable made from Python code???

 

Regards

Sandy
 
> From: pmau...@gmail.com
> Subject: Re: where are the program that are written in python?
> Date: Fri, 21 May 2010 23:29:37 -0700
> To: python-list@python.org
> 
> On May 21, 9:12 pm, Ben Finney  wrote:
> > a...@pythoncraft.com (Aahz) writes:
> > > In article 
> > > ,
> > > Patrick Maupin   wrote:
> >
> > > >There are a lot of commercial programs written in Python.  But any
> > > >company which thinks it has a lock on some kind of super secret sauce
> > > >isn't going to use Python, because it's very easy to reverse engineer
> > > >even compiled Python programs.  
> >
> > > That's not always true.  Both my employer (Egnyte) and one of our main
> > > competitors (Dropbox) use Python in our clients.  We don't care much
> > > because using our servers is a requirement of the client.
> >
> > Doesn't that mean those companies don't fit the above description? That
> > is, neither of them “thinks it has a lock on some kind of super secret
> > sauce” in the programs. So they don't seem to be counter-examples.
> 
> Just because someone has competition doesn't mean they don't think
> they have secret sauce. I think Aahz's main point was that in his sub-
> industry, the secret sauce is guarded by not actually letting the
> customer have access to executable code, other than through the
> network.
> 
> Regards,
> Pat
> -- 
> http://mail.python.org/mailman/listinfo/python-list
  
_
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
https://signup.live.com/signup.aspx?id=60969-- 
http://mail.python.org/mailman/listinfo/python-list


Re: asyncore loop and cmdloop problem

2010-05-25 Thread Michele Simionato
On May 25, 2:56 pm, "kak...@gmail.com"  wrote:
> Could you please provide me with a simple example how to do this with
> threads.
> I don't know where to put the cmdloop().
> Please help, i' m so confused!
> Thank you

What are you trying to do? Do you really need to use the standard
library? Likely what you want to accomplish is already implemented in
Twisted; I remember there was something like that in their examples
directory.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: asyncore loop and cmdloop problem

2010-05-25 Thread kak...@gmail.com
On May 25, 5:23 pm, Michele Simionato 
wrote:
> On May 25, 2:56 pm, "kak...@gmail.com"  wrote:
>
> > Could you please provide me with a simple example how to do this with
> > threads.
> > I don't know where to put the cmdloop().
> > Please help, i' m so confused!
> > Thank you
>
> What are you trying to do? Do you really need to use the standard
> library? Likely what you want to accomplish is already implemented in
> Twisted; I remember there was something like that in their examples
> directory.

Thank you,
and sorry for the mistake i did before with my post.

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


Re: to prevent reveres engineering for Python

2010-05-25 Thread Adam Tauno Williams
On Tue, 2010-05-25 at 18:49 +0500, Sandy Ydnas wrote:
> Agree, reveres engineering is crucial issuer  for programming
> language 
> but every executable file can be cracked, for example  by using
> disassembler!!! 
> For each weapon there is antiweapon, so
> is it possible to prevent reveres engineering when customer have
> access to executable made from Python code???

No.  But you can make it hard.

Store a GPG encrypted blob in your program that contains you secret
sauce, is decrypted to memory, executed, and then discarded.Setup
some kind of license manager like dongle or application to perform the
key management.
-- 
Adam Tauno Williams  LPIC-1, Novell CLA

OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba

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


Re: asyncore loop and cmdloop problem

2010-05-25 Thread kak...@gmail.com
On May 25, 5:47 pm, "kak...@gmail.com"  wrote:
> On May 25, 5:23 pm, Michele Simionato 
> wrote:
>
> > On May 25, 2:56 pm, "kak...@gmail.com"  wrote:
>
> > > Could you please provide me with a simple example how to do this with
> > > threads.
> > > I don't know where to put the cmdloop().
> > > Please help, i' m so confused!
> > > Thank you
>
> > What are you trying to do? Do you really need to use the standard
> > library? Likely what you want to accomplish is already implemented in
> > Twisted; I remember there was something like that in their examples
> > directory.
>
> Thank you,
> and sorry for the mistake i did before with my post.
>
> Antonis

hi again. i installed twisted, but since i m not familiar with it, do
you remember which example you have in mind?
What i want to accomplish is something like "asterisk". while you send
commands from the asterisk cli, at the same time
the underlying protocol sends you notifications to the console.
without exiting the application.
thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generator expressions vs. comprehensions

2010-05-25 Thread Terry Reedy

On 5/25/2010 3:08 AM, Peter Otten wrote:

Michele Simionato wrote:



I think not turning the list-comp into syntactic sugar for list(genexp) in
py3 is a missed opportunity.


Implementing it that way was tried but was much slower than the current 
implementation. If one uses StopIteration as it is intended to be used 
(and is so documented), then, I believe, they are equivalent. There was 
a conscious decision to not slow comprehensions for the many to cater to 
the very few.


Terry Jan Reedy

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


Re: to prevent reveres engineering for Python

2010-05-25 Thread Terry Reedy

On 5/25/2010 9:49 AM, Sandy Ydnas wrote:


is it possible to prevent reveres engineering when customer have access
to executable made from Python code???


If there is, it is a trade secrets that you will not be able to reverse 
engineer ;-).


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


Re: Generator expressions vs. comprehensions

2010-05-25 Thread Terry Reedy

On 5/25/2010 1:09 PM, Terry Reedy wrote:

On 5/25/2010 3:08 AM, Peter Otten wrote:

Michele Simionato wrote:



I think not turning the list-comp into syntactic sugar for
list(genexp) in
py3 is a missed opportunity.


Implementing it that way was tried but was much slower than the current
implementation. If one uses StopIteration as it is intended to be used
(and is so documented), then, I believe, they are equivalent. There was
a conscious decision to not slow comprehensions for the many to cater to
the very few.


And those few can always write list(genexp) instead of [genexp] (or 
set...) when the minute difference actually matters.



Terry Jan Reedy




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


Troubles with python internationalization

2010-05-25 Thread Pascal Chambon

Hello

I'm studying the migration of my website (mixed english and french
languages...) to a properly localized architecture.

From what I've read so far, using translation "tags" (or quick phrases)
in the code, and translating them to every target language (including
english) sounds a better approach than using, for example, final english
wordings as translation tags. The setup is longer via the first way, but
at least if you change english wordings later, you don't break all other
translations at the same time.

However, I still have problems with some aspects of internationalization:

* code safety : it seems default python string formatting technics (%
operator, .format() method) are normally used when one needs to
substitute placeholders in translated strings. But the thing is : I DONT
want my view to raise an exception simply because one of the
translations has forgotten a damn "%(myvar)s" placeholder. The only
quick fix I can think of, is to always use substitution through
defaultdicts instances (and still, exceptions could occur if abnormal
"%s" placeholders are found in the translated string).
Are there some utilities in python, or frameworks like django,
 to allow a safe string substitution (which might,
for example, simply log an error if a buggy string si found)  ? Python's
template strings' "safe_substitute()" won't fit, because it swallows
errors without any notice...

* unknown translatable strings : I have in different data files (eg.
yaml), strings which will need translation, but that can't be detected
by gettext and co, since they only appear in the code as variable i.e
"_(yamlvar)". The easiest, I guess, would be to replace them by specific
tags (like "TR_HOMEPAGE_TITLE"), and to have a tool browse the code to
extract them and add them to the standard gettext translation chain.
Such a tool shouldn't be too hard to code, but I'd rather know : doesn't
such a tool already exist somewhere ? I've seen no such mention in
gettext or babel tools, only recogniztion via function calls ( _(),
tr()... ).

* I have seen nowhere mention of how to remove deprecated/unused strings
from gettext files - only merging translations seems to interest people.
However, having a translation file which slowly fills itself with
outdated data doesn't sound cool to me. Does anyone know tools/program
flags which would list/extract translations that don't seem used anymore ?


Thanks for you help,

regards,
Pascal


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


Another Little MySQL Problem

2010-05-25 Thread Victor Subervi
Hi;
I have this code:

clientCursor.execute('select ID from %s' % (personalDataTable))
upds = [itm[0] for itm in clientCursor]
print "" % upds

The problem is that the values passed are 1L, 2L When I retrieve them on
the other end and try to convert them to integers, guess what happens? So
how do I get rid of that "L"?
TIA,
beno
-- 
http://mail.python.org/mailman/listinfo/python-list


Legal Point Dhaka bangladesh

2010-05-25 Thread Minhaz Rahman
http://www.advocatemizan.com

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


speed up a numpy code with huge array

2010-05-25 Thread Alexzive
Hello Pythonguys!

is there a way to improve the performance of the attached code ? it
takes about 5 h on a dual-core (using only one core) when len(V)
~1MIL. V is an array which is supposed to store all the volumes of
tetrahedral elements of a grid whose coord. are stored in NN (accessed
trough the list of tetraelements --> EL)


Thanks in advance!
Alex


print 'start ' + nameodb
#path = '/windows/D/SIM-MM/3D/E_ortho/' + nameodb + '.odb'
path = pt + nameodb + '.odb'
odb = openOdb(path)

N = odb.rootAssembly.instances['PART-1-1'].nodes
if loadV==1:
  pathV=pt+vtet
  V=numpy.loadtxt(pathV)
  VTOT = V[0]
  L3 = V[1]
  print 'using ' + vtet
else:
  NN=[]
  B=[0,0,0,0]
  for i in range(len(N)):
B[0] = N[i].label
B[1] = N[i].coordinates[0]
B[2] = N[i].coordinates[1]
B[3] = N[i].coordinates[2]
NN = append(NN,B)

  NN=NN.reshape(-1,4)
  EL = odb.rootAssembly.instances['PART-1-1'].elements

  L1 = max(NN[:,1])-min(NN[:,1])
  L2 = max(NN[:,2])-min(NN[:,2])
  L3 = max(NN[:,3])-min(NN[:,3])
  VTOT=L1*L2*L3
  print 'VTOT: [mm³]' + str(VTOT)

  V = array([])

  print 'calculating new Vtet '
  V = range(len(EL)+2)
  V[0] = VTOT
  V[1] = L3
  for j in range(0,len(EL)):
Va = EL[j].connectivity[0]
Vb = EL[j].connectivity[1]
Vc = EL[j].connectivity[2]
Vd = EL[j].connectivity[3]
ix = where(NN[:,0] == Va)
Xa = NN[ix,1][0][0]
Ya = NN[ix,2][0][0]
Za = NN[ix,3][0][0]
ix = where(NN[:,0] == Vb)
Xb = NN[ix,1][0][0]
Yb = NN[ix,2][0][0]
Zb = NN[ix,3][0][0]
ix = where(NN[:,0] == Vc)
Xc = NN[ix,1][0][0]
Yc = NN[ix,2][0][0]
Zc = NN[ix,3][0][0]
ix = where(NN[:,0] == Vd)
Xd = NN[ix,1][0][0]
Yd = NN[ix,2][0][0]
Zd = NN[ix,3][0][0]
a =  [Xa,Ya,Za]
b =  [Xb,Yb,Zb]
c =  [Xc,Yc,Zc]
d =  [Xd,Yd,Zd]
aa = numpy.diff([b,a],axis=0)[0]
bb = numpy.diff([c,b],axis=0)[0]
cc = numpy.diff([d,c],axis=0)[0]
D=array([aa,bb,cc])
det=numpy.linalg.det(D)
V[j+2] = abs(det)/6
  pathV = pt + vtet
  savetxt(pathV, V, fmt='%.3e')
###
-- 
http://mail.python.org/mailman/listinfo/python-list


UnicodeDecodeError having fetch web page

2010-05-25 Thread Barry
Hi,

The code below is giving me the error:

Traceback (most recent call last):
  File "C:\Users\Administratör\Desktop\test.py", line 4, in 
UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position 1:
unexpected code byte


What am i doing wrong?

Thanks,

Barry

request = urllib.request.Request(url='http://en.wiktionary.org/wiki/
baby',headers={'User-Agent':'Mozilla/5.0 (X11; U; Linux i686) Gecko/
20071127 Firefox/2.0.0.11'} )

response = urllib.request.urlopen(request)
html = response.read().decode('utf-8')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: speed up a numpy code with huge array

2010-05-25 Thread Vincent Davis
It makes me think you are filling you available memory and using the disk as
cache. If this happens things will get real slow. You might take a look at
your system resources when this is running. I don't have much else to offer
and could be completely wrong.

Vincent

On Tue, May 25, 2010 at 1:05 PM, Alexzive  wrote:

> Hello Pythonguys!
>
> is there a way to improve the performance of the attached code ? it
> takes about 5 h on a dual-core (using only one core) when len(V)
> ~1MIL. V is an array which is supposed to store all the volumes of
> tetrahedral elements of a grid whose coord. are stored in NN (accessed
> trough the list of tetraelements --> EL)
>
>
> Thanks in advance!
> Alex
>
> 
> print 'start ' + nameodb
> #path = '/windows/D/SIM-MM/3D/E_ortho/' + nameodb + '.odb'
> path = pt + nameodb + '.odb'
> odb = openOdb(path)
>
> N = odb.rootAssembly.instances['PART-1-1'].nodes
> if loadV==1:
>  pathV=pt+vtet
>  V=numpy.loadtxt(pathV)
>  VTOT = V[0]
>  L3 = V[1]
>  print 'using ' + vtet
> else:
>  NN=[]
>  B=[0,0,0,0]
>  for i in range(len(N)):
>B[0] = N[i].label
>B[1] = N[i].coordinates[0]
>B[2] = N[i].coordinates[1]
>B[3] = N[i].coordinates[2]
>NN = append(NN,B)
>
>  NN=NN.reshape(-1,4)
>  EL = odb.rootAssembly.instances['PART-1-1'].elements
>
>  L1 = max(NN[:,1])-min(NN[:,1])
>  L2 = max(NN[:,2])-min(NN[:,2])
>  L3 = max(NN[:,3])-min(NN[:,3])
>  VTOT=L1*L2*L3
>  print 'VTOT: [mm³]' + str(VTOT)
>
>  V = array([])
>
>  print 'calculating new Vtet '
>  V = range(len(EL)+2)
>  V[0] = VTOT
>  V[1] = L3
>  for j in range(0,len(EL)):
>Va = EL[j].connectivity[0]
>Vb = EL[j].connectivity[1]
>Vc = EL[j].connectivity[2]
>Vd = EL[j].connectivity[3]
>ix = where(NN[:,0] == Va)
>Xa = NN[ix,1][0][0]
>Ya = NN[ix,2][0][0]
>Za = NN[ix,3][0][0]
>ix = where(NN[:,0] == Vb)
>Xb = NN[ix,1][0][0]
>Yb = NN[ix,2][0][0]
>Zb = NN[ix,3][0][0]
>ix = where(NN[:,0] == Vc)
>Xc = NN[ix,1][0][0]
>Yc = NN[ix,2][0][0]
>Zc = NN[ix,3][0][0]
>ix = where(NN[:,0] == Vd)
>Xd = NN[ix,1][0][0]
>Yd = NN[ix,2][0][0]
>Zd = NN[ix,3][0][0]
>a =  [Xa,Ya,Za]
>b =  [Xb,Yb,Zb]
>c =  [Xc,Yc,Zc]
>d =  [Xd,Yd,Zd]
>aa = numpy.diff([b,a],axis=0)[0]
>bb = numpy.diff([c,b],axis=0)[0]
>cc = numpy.diff([d,c],axis=0)[0]
>D=array([aa,bb,cc])
>det=numpy.linalg.det(D)
>V[j+2] = abs(det)/6
>  pathV = pt + vtet
>  savetxt(pathV, V, fmt='%.3e')
> ###
> --
> http://mail.python.org/mailman/listinfo/python-list
>

  *Vincent Davis
720-301-3003 *
vinc...@vincentdavis.net
 my blog  |
LinkedIn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError having fetch web page

2010-05-25 Thread Philip Semanchuk


On May 25, 2010, at 3:13 PM, Barry wrote:


Hi,

The code below is giving me the error:

Traceback (most recent call last):
 File "C:\Users\Administratör\Desktop\test.py", line 4, in 
UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position 1:
unexpected code byte


What am i doing wrong?

Thanks,

Barry

request = urllib.request.Request(url='http://en.wiktionary.org/wiki/
baby',headers={'User-Agent':'Mozilla/5.0 (X11; U; Linux i686) Gecko/
20071127 Firefox/2.0.0.11'} )

response = urllib.request.urlopen(request)
html = response.read().decode('utf-8')



Well, for starters you're assuming that the response content is in  
UTF-8. You need to examine the Content-Type header to see what the  
encoding is. If it's not UTF-8, there's your problem.



HTH
P

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


Re: to prevent reveres engineering for Python

2010-05-25 Thread Lie Ryan
On 05/26/10 01:09, Adam Tauno Williams wrote:
> On Tue, 2010-05-25 at 18:49 +0500, Sandy Ydnas wrote:
>> Agree, reveres engineering is crucial issuer  for programming
>> language 
>> but every executable file can be cracked, for example  by using
>> disassembler!!! 
>> For each weapon there is antiweapon, so
>> is it possible to prevent reveres engineering when customer have
>> access to executable made from Python code???
> 
> No.  But you can make it hard.
> 
> Store a GPG encrypted blob in your program that contains you secret
> sauce, is decrypted to memory, executed, and then discarded.Setup
> some kind of license manager like dongle or application to perform the
> key management.

That merely gives a false sense of security. If the program is decrypted
in memory, you can easily make a memory dump to get the unencrypted
program. If I am a competitor that can make economic advantage by
cracking your secret sauce, it wouldn't be difficult for me to do that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: to prevent reveres engineering for Python

2010-05-25 Thread D'Arcy J.M. Cain
On Wed, 26 May 2010 05:40:43 +1000
Lie Ryan  wrote:
> That merely gives a false sense of security. If the program is decrypted
> in memory, you can easily make a memory dump to get the unencrypted
> program. If I am a competitor that can make economic advantage by
> cracking your secret sauce, it wouldn't be difficult for me to do that.

Yes, in fact the only people inconvenienced are your paying clients.

-- 
D'Arcy J.M. Cain  |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 80, Issue 223

2010-05-25 Thread Ian Kelly
On Tue, May 25, 2010 at 1:10 PM,   wrote:
> -- Forwarded message --
> From: Terry Reedy 
> To: python-l...@python.org
> Date: Tue, 25 May 2010 13:09:23 -0400
> Subject: Re: Generator expressions vs. comprehensions
> On 5/25/2010 3:08 AM, Peter Otten wrote:
>>
>> Michele Simionato wrote:
>
>> I think not turning the list-comp into syntactic sugar for list(genexp) in
>> py3 is a missed opportunity.
>
> Implementing it that way was tried but was much slower than the current 
> implementation. If one uses StopIteration as it is intended to be used (and 
> is so documented), then, I believe, they are equivalent. There was a 
> conscious decision to not slow comprehensions for the many to cater to the 
> very few.

I thought that I was using it as intended.  The full function that I
was working with when I ran into the problem was:

def tuples(iterable, n=2):
"""Make an iterator that returns elements from iterable in tuples of n.  If
the number of elements from the iterable is not a multiple of n, any
trailing elements will be truncated.

tuples('ABCDEFG', n=2) --> ('A', 'B') ('C', 'D') ('E', 'F')
"""
iterator = iter(iterable)
while True:
yield tuple(iterator.next() for i in xrange(n))

The intention being that if iterator.next() raised a StopIteration, it
would propagate out and signal no further values for the tuples
generator.  Instead, the generator expression results in empty tuples
once the iterator has run out, and the tuples generator never runs
out.  This has since been fixed by replacing the generator expression
with a for loop, but if you don't mind my asking, how does this
violate the documented usage pattern?  Is the recommendation to use an
explicit try-except around every call of iterator.next()?

Off-topic, does anybody know of a better name for this function?

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


Re: UnicodeDecodeError having fetch web page

2010-05-25 Thread Barry
On 25 Maj, 21:39, Philip Semanchuk  wrote:
> On May 25, 2010, at 3:13 PM, Barry wrote:
>
>
>
> > Hi,
>
> > The code below is giving me the error:
>
> > Traceback (most recent call last):
> >  File "C:\Users\Administratör\Desktop\test.py", line 4, in 
> > UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position 1:
> > unexpected code byte
>
> > What am i doing wrong?
>
> > Thanks,
>
> > Barry
>
> > request = urllib.request.Request(url='http://en.wiktionary.org/wiki/
> > baby',headers={'User-Agent':'Mozilla/5.0 (X11; U; Linux i686) Gecko/
> > 20071127 Firefox/2.0.0.11'} )
>
> > response = urllib.request.urlopen(request)
> > html = response.read().decode('utf-8')
>
> Well, for starters you're assuming that the response content is in  
> UTF-8. You need to examine the Content-Type header to see what the  
> encoding is. If it's not UTF-8, there's your problem.
>
> HTH
> P

The content type is utf-8:

Date: Wed, 19 May 2010 19:17:39 GMT
Server: Apache
Cache-Control: private, s-maxage=0, max-age=0, must-revalidate
Content-Language: en
Vary: Accept-Encoding,Cookie
Last-Modified: Wed, 19 May 2010 10:10:34 GMT
Content-Encoding: gzip
Content-Length: 25247
Content-Type: text/html; charset=utf-8
X-Cache: HIT from sq61.wikimedia.org
X-Cache-Lookup: HIT from sq61.wikimedia.org:3128
Age: 520549
X-Cache: HIT from amssq32.esams.wikimedia.org
X-Cache-Lookup: HIT from amssq32.esams.wikimedia.org:3128
X-Cache: MISS from amssq37.esams.wikimedia.org
X-Cache-Lookup: MISS from amssq37.esams.wikimedia.org:80
Connection: close

Can it be that the page is corrupt? If so, how can I make the best of
the situation? Many other pages from this server work without problem.

Thanks!

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


Re: to prevent reveres engineering for Python

2010-05-25 Thread Grant Edwards
On 2010-05-25, D'Arcy J.M. Cain  wrote:
> On Wed, 26 May 2010 05:40:43 +1000
> Lie Ryan  wrote:
>
>> That merely gives a false sense of security. If the program is
>> decrypted in memory, you can easily make a memory dump to get the
>> unencrypted program. If I am a competitor that can make economic
>> advantage by cracking your secret sauce, it wouldn't be difficult for
>> me to do that.
>
> Yes, in fact the only people inconvenienced are your paying clients.

After several bad experiences over the years, I'm now willing go to
quite a bit of effort to avoid using products that require dongles,
node-locked licenses or license servers.

-- 
Grant Edwards   grant.b.edwardsYow! Hold the MAYO & pass
  at   the COSMIC AWARENESS ...
  gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 80, Issue 223

2010-05-25 Thread Chris Rebert
On Tue, May 25, 2010 at 1:01 PM, Ian Kelly  wrote:
> On Tue, May 25, 2010 at 1:10 PM,   wrote:
>> -- Forwarded message --
>> From: Terry Reedy 
>> To: python-l...@python.org
>> Date: Tue, 25 May 2010 13:09:23 -0400
>> Subject: Re: Generator expressions vs. comprehensions
>> On 5/25/2010 3:08 AM, Peter Otten wrote:
>>>
>>> Michele Simionato wrote:
>>
>>> I think not turning the list-comp into syntactic sugar for list(genexp) in
>>> py3 is a missed opportunity.
>>
>> Implementing it that way was tried but was much slower than the current 
>> implementation. If one uses StopIteration as it is intended to be used (and 
>> is so documented), then, I believe, they are equivalent. There was a 
>> conscious decision to not slow comprehensions for the many to cater to the 
>> very few.
>
> I thought that I was using it as intended.  The full function that I
> was working with when I ran into the problem was:
>
> def tuples(iterable, n=2):
>    """Make an iterator that returns elements from iterable in tuples of n.  If
>    the number of elements from the iterable is not a multiple of n, any
>    trailing elements will be truncated.
>
>    tuples('ABCDEFG', n=2) --> ('A', 'B') ('C', 'D') ('E', 'F')
>    """
>    iterator = iter(iterable)
>    while True:
>        yield tuple(iterator.next() for i in xrange(n))
>
> The intention being that if iterator.next() raised a StopIteration, it
> would propagate out and signal no further values for the tuples
> generator.  Instead, the generator expression results in empty tuples
> once the iterator has run out, and the tuples generator never runs
> out.  This has since been fixed by replacing the generator expression
> with a for loop, but if you don't mind my asking, how does this
> violate the documented usage pattern?  Is the recommendation to use an
> explicit try-except around every call of iterator.next()?
>
> Off-topic, does anybody know of a better name for this function?

truncating_grouper() ?

from itertools import izip
def truncating_grouper(n, iterable):
"truncating_grouper(3, 'ABCDEFG') --> ABC DEF"
args = [iter(iterable)] * n
return izip(*args)

Implementation adapted from itertools's docs's "Recipes" section.

Also, avoid replying to digests in the future; it messes up
conversation threading.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UnicodeDecodeError having fetch web page

2010-05-25 Thread Peter Otten
Barry wrote:

> On 25 Maj, 21:39, Philip Semanchuk  wrote:
>> On May 25, 2010, at 3:13 PM, Barry wrote:
>>
>>
>>
>> > Hi,
>>
>> > The code below is giving me the error:
>>
>> > Traceback (most recent call last):
>> > File "C:\Users\Administratör\Desktop\test.py", line 4, in 
>> > UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position 1:
>> > unexpected code byte
>>
>> > What am i doing wrong?
>>
>> > Thanks,
>>
>> > Barry
>>
>> > request = urllib.request.Request(url='http://en.wiktionary.org/wiki/
>> > baby',headers={'User-Agent':'Mozilla/5.0 (X11; U; Linux i686) Gecko/
>> > 20071127 Firefox/2.0.0.11'} )
>>
>> > response = urllib.request.urlopen(request)
>> > html = response.read().decode('utf-8')
>>
>> Well, for starters you're assuming that the response content is in
>> UTF-8. You need to examine the Content-Type header to see what the
>> encoding is. If it's not UTF-8, there's your problem.
>>
>> HTH
>> P
> 
> The content type is utf-8:
> 
> Date: Wed, 19 May 2010 19:17:39 GMT
> Server: Apache
> Cache-Control: private, s-maxage=0, max-age=0, must-revalidate
> Content-Language: en
> Vary: Accept-Encoding,Cookie
> Last-Modified: Wed, 19 May 2010 10:10:34 GMT
> Content-Encoding: gzip

But the data is gzipped. You have to uncompress it before decoding.

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


Re: UnicodeDecodeError having fetch web page

2010-05-25 Thread Rob Williscroft
Barry wrote in news:83dc485a-5a20-403b-99ee-c8c627bdbab3
@m21g2000vbr.googlegroups.com in gmane.comp.python.general:

> Hi,
> 
> The code below is giving me the error:
> 
> Traceback (most recent call last):
>   File "C:\Users\Administratör\Desktop\test.py", line 4, in 
> UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position 1:
> unexpected code byte
> 
> 
> What am i doing wrong?

It may not be you, en.wiktionary.org is sending gzip 
encoded content back, it seems to do this even if you set
the Accept header as in:

request.add_header( "Accept", "text/html" )

But maybe I'm not doing it correctly.

#encoding: utf-8
import urllib
import urllib.request

request = urllib.request.Request
(url='http://en.wiktionary.org/wiki/baby',headers={'User-
Agent':'Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 
Firefox/2.0.0.11'} )

response = urllib.request.urlopen(request)
info = response.info()
enc = info[ 'Content-Encoding' ]
print( "Encoding: " + enc )

from io import BytesIO
import gzip

buf = BytesIO( response.read() )
unziped = gzip.GzipFile( "wahatever", mode = 'rb', fileobj = buf )
html = unziped.read().decode('utf-8')

print( html.encode( "ascii", "backslashreplace" ) )

Rob.

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


Re: UnicodeDecodeError having fetch web page

2010-05-25 Thread Philip Semanchuk


On May 25, 2010, at 4:00 PM, Barry wrote:


On 25 Maj, 21:39, Philip Semanchuk  wrote:

On May 25, 2010, at 3:13 PM, Barry wrote:




Hi,



The code below is giving me the error:



Traceback (most recent call last):
 File "C:\Users\Administratör\Desktop\test.py", line 4, in 
UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in  
position 1:

unexpected code byte



What am i doing wrong?



Thanks,



Barry



request = urllib.request.Request(url='http://en.wiktionary.org/wiki/
baby',headers={'User-Agent':'Mozilla/5.0 (X11; U; Linux i686) Gecko/
20071127 Firefox/2.0.0.11'} )



response = urllib.request.urlopen(request)
html = response.read().decode('utf-8')


Well, for starters you're assuming that the response content is in
UTF-8. You need to examine the Content-Type header to see what the
encoding is. If it's not UTF-8, there's your problem.

HTH
P


The content type is utf-8:

Date: Wed, 19 May 2010 19:17:39 GMT
Server: Apache
Cache-Control: private, s-maxage=0, max-age=0, must-revalidate
Content-Language: en
Vary: Accept-Encoding,Cookie
Last-Modified: Wed, 19 May 2010 10:10:34 GMT
Content-Encoding: gzip
Content-Length: 25247
Content-Type: text/html; charset=utf-8
X-Cache: HIT from sq61.wikimedia.org
X-Cache-Lookup: HIT from sq61.wikimedia.org:3128
Age: 520549
X-Cache: HIT from amssq32.esams.wikimedia.org
X-Cache-Lookup: HIT from amssq32.esams.wikimedia.org:3128
X-Cache: MISS from amssq37.esams.wikimedia.org
X-Cache-Lookup: MISS from amssq37.esams.wikimedia.org:80
Connection: close


Looks like the content is gzipped. Have you unzipped it? Also, from  
where are you getting those headers? The server might well send  
different headers to your browser than to a urllib request.


Have you examined the raw content in a hex editor on in the debugger?  
That would probably answer a lot of questions.




Can it be that the page is corrupt?


Of course that's always possible, but personally whenever I have to  
decide whether bits are being flipped at random or my code is buggy,  
it's almost always the latter.



If so, how can I make the best of the situation?


Depends on what you're trying to accomplish.



bye
Philip





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


Re: to prevent reveres engineering for Python

2010-05-25 Thread Adam Tauno Williams
On Wed, 2010-05-26 at 05:40 +1000, Lie Ryan wrote:
> On 05/26/10 01:09, Adam Tauno Williams wrote:
> > On Tue, 2010-05-25 at 18:49 +0500, Sandy Ydnas wrote:
> >> Agree, reveres engineering is crucial issuer  for programming
> >> language 
> >> but every executable file can be cracked, for example  by using
> >> disassembler!!! 
> >> For each weapon there is antiweapon, so
> >> is it possible to prevent reveres engineering when customer have
> >> access to executable made from Python code???
> > No.  But you can make it hard.
> > Store a GPG encrypted blob in your program that contains you secret
> > sauce, is decrypted to memory, executed, and then discarded.Setup
> > some kind of license manager like dongle or application to perform the
> > key management.
> That merely gives a false sense of security. 

There is no "true" sense of security.  There is only degrees of
obfuscation, hence the first sentence: "No. But you can make it hard"

> If the program is decrypted
> in memory, you can easily make a memory dump

Easily?  Really?  You vastly over estimate the majority of computer
users.  If someone who knows how to read the memory of a running process
wants your secret sauce - they are going to get it.

>  to get the unencrypted
> program. If I am a competitor that can make economic advantage by
> cracking your secret sauce, it wouldn't be difficult for me to do that.

True.  That is pretty much always true.  The only effective solution is
to have your app call a web service [or some kind of RPC] to a server
where you keep the secret sauce hidden away.


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


Re: to prevent reveres engineering for Python

2010-05-25 Thread Daniel Fetchinson
>> is it possible to prevent reveres engineering when customer have access
>> to executable made from Python code???

The only secure way of protecting your code is if you expose it as a
web service or some such. (Yes, people can still crack your web
server, but that's nitpicking :))

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: to prevent reveres engineering for Python

2010-05-25 Thread Ben Finney
Terry Reedy  writes:

> On 5/25/2010 9:49 AM, Sandy Ydnas wrote:
>
> > is it possible to prevent reveres engineering when customer have
> > access to executable made from Python code???
>
> If there is, it is a trade secrets that you will not be able to
> reverse engineer ;-).

+1 QOTW

-- 
 \  “The best way to get information on Usenet is not to ask a |
  `\   question, but to post the wrong information.” —Aahz |
_o__)  |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: asyncore loop and cmdloop problem

2010-05-25 Thread exarkun

On 04:31 pm, kak...@gmail.com wrote:

On May 25, 5:47�pm, "kak...@gmail.com"  wrote:

On May 25, 5:23�pm, Michele Simionato 
wrote:

> On May 25, 2:56�pm, "kak...@gmail.com"  wrote:

> > Could you please provide me with a simple example how to do this 
with

> > threads.
> > I don't know where to put the cmdloop().
> > Please help, i' m so confused!
> > Thank you

> What are you trying to do? Do you really need to use the standard
> library? Likely what you want to accomplish is already implemented 
in

> Twisted; I remember there was something like that in their examples
> directory.

Thank you,
and sorry for the mistake i did before with my post.

Antonis


hi again. i installed twisted, but since i m not familiar with it, do
you remember which example you have in mind?
What i want to accomplish is something like "asterisk". while you send
commands from the asterisk cli, at the same time
the underlying protocol sends you notifications to the console.
without exiting the application.
thanks


You can find a couple simple examples here:

 http://twistedmatrix.com/documents/current/core/examples/

Search for "stdin" and "stdio".

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


Re: function that counts...

2010-05-25 Thread Bryan
Raymond Hettinger wrote:
> If speed is important, the global lookups can be localized:
>
> def prttn(m, n, map=itertools.imap, int=int, str=str, range=range):
>     return sum(m == sum(map(int, str(x))) for x in range(n))

That's just silly. "If speed is important," we abandon the naive
algorithm.


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


Re: function that counts...

2010-05-25 Thread Bryan
Jean-Michel Pichavant wrote:
> I still don't see "how many positive integers less than n have digits
> that sum up to m" makes it a "partition" though if that what prttn
> means. Surely because I miss the context.

A partition of a positive integer m is an unordered collection of
positive integers that sum to m. [1, 1, 2, 5] is a partition of 9. The
problem at issue here is not that of counting partitions.

My algorithm for our prttn separated out the 'ndsums' sub-problem:
Count d-digit ints with digits summing to m. I found a generalization
of that problem stated in the /CRC Handbook of Discrete and
Combinatorial Mathematics/ (2000 edition, section 2.1) among "counting
problems" as:

   Solutions to x_1 + ... x_n = k
   0 <= x_i <= a_i for one or more i

Alas, the handbook does not provide a formula or algorithm. It refers
to the inclusion/exclusion principle, which I did not see how to turn
into an efficient algorithm.

My recursive memoizing method for ndsums() was initially a shot in the
dark and I was surprised how well it worked. Thinking about it more, I
can argue that it is polynomial-time based on the size of the memo-
table and the work per entry. My prttn() calls ndsums() once for each
digit, so the whole thing is polynomial in the number of digits.


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


Need some Python 3 help

2010-05-25 Thread Paul McGuire
I was teetering on the brink of releasing Pyparsing 1.5.3 (with some
nice new examples and goodies), when I saw that I had recently
introduced a bug in the Python 3 compatible version.  Here is the
stacktrace as reported on SF:

Traceback (most recent call last):
File "testcase.py", line 11, in 
result = exp.parseFile("./pyparsing_py3.py")
File "/data/projekte/parsing/pyparsing/pyparsing_py3.py", line 1426,
in parseFile
return self.parseString(file_contents, parseAll)
File "/data/projekte/parsing/pyparsing/pyparsing_py3.py", line 1068,
in parseString
loc, tokens = self._parse( instring, 0 )
File "/data/projekte/parsing/pyparsing/pyparsing_py3.py", line 935, in
_parseNoCache
preloc = self.preParse( instring, loc )
File "/data/projekte/parsing/pyparsing/pyparsing_py3.py", line 893, in
preParse
while loc < instrlen and instring[loc] in wt:
TypeError: 'in ' requires string as left operand, not int

In this section of code, instring is a string, loc is an int, and wt
is a string.  Any clues why instring[loc] would be evaluating as int?
(I am unfortunately dependent on the kindness of strangers when it
comes to testing my Python 3 code, as I don't have a Py3 environment
installed.)

Thanks,
-- Paul
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need some Python 3 help

2010-05-25 Thread Benjamin Peterson
Paul McGuire  austin.rr.com> writes:
> In this section of code, instring is a string, loc is an int, and wt
> is a string.  Any clues why instring[loc] would be evaluating as int?
> (I am unfortunately dependent on the kindness of strangers when it
> comes to testing my Python 3 code, as I don't have a Py3 environment
> installed.)

Indexing bytes in Python 3 gives an integer.




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


Re: Need some Python 3 help

2010-05-25 Thread Bryan
Paul McGuire  wrote:
[...]
> while loc < instrlen and instring[loc] in wt:
> TypeError: 'in ' requires string as left operand, not int
>
> In this section of code, instring is a string, loc is an int,

In Python 3, lots of things that used to return str now return bytes,
and the elements of a bytes object are ints. Something to check.

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


Re: Need some Python 3 help

2010-05-25 Thread Paul McGuire
On May 25, 8:58 pm, Benjamin Peterson  wrote:
> Paul McGuire  austin.rr.com> writes:
>
> > In this section of code, instring is a string, loc is an int, and wt
> > is a string.  Any clues why instring[loc] would be evaluating as int?
> > (I am unfortunately dependent on the kindness of strangers when it
> > comes to testing my Python 3 code, as I don't have a Py3 environment
> > installed.)
>
> Indexing bytes in Python 3 gives an integer.

Hrmm, I had a sneaking hunch this might be the issue.  But then I
don't know how this code *ever* worked in Python 3, as it is chock
full of indexed references into the string being parsed.  And yet,
I've had other folks test and confirm that pyparsing_py3 *does* work
on Python 3.  It is a puzzle.

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


Re: Need some Python 3 help

2010-05-25 Thread Bryan
Paul McGuire wrote:
> Hrmm, I had a sneaking hunch this might be the issue.  But then I
> don't know how this code *ever* worked in Python 3, as it is chock
> full of indexed references into the string being parsed.  And yet,
> I've had other folks test and confirm that pyparsing_py3 *does* work
> on Python 3.  It is a puzzle.

I suspect in most cases you use bytes consistently. You got the
exception from:

  instring[loc] in wt

If instring and wt are both bytes, that's fine. If they're both str,
also fine. If one is bytes and one is str, exception.


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


Re: [wxPython-users] wxPython 2.8.11.0 release

2010-05-25 Thread Godson Gera
On Tue, May 25, 2010 at 5:08 AM, Robin Dunn  wrote:

> Announcing
> --
>
> The 2.8.11.0 release of wxPython is now available for download at
> http://wxpython.org/download.php. This release adds Python 2.7 builds,
> PySlices, new pubsub implementation, lots of updates to AGW, and lots
> of bugs fixed.  A summary of changes is listed below and also at
> http://wxpython.org/recentchanges.php.
>
>
Thanks for the great work !

-- 
Thanks & Regards,
Godson Gera
IVR India 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP 3119 ABC - And how I learned to love the Abstract Bomb

2010-05-25 Thread Pykler
On May 13, 9:30 am, Lawrence D'Oliveiro  wrote:
> You’re looking at it wrong. If you want to force people to do things in a
> certain way, use Java. Python is about enabling things, not forcing them.

LoL :-)

> Don’t use subclassing. Instead, let the caller pass you a duck-typed object
> that implements the methods you need.

I totally agree. in my code I do not force the object to be an
instance of a subclass of the ABC, they certainly can duck-type as
they please. The ABC is simply there to give them an idea of what
methods they need to implement. It is kind of self documenting
structure if you may. However, I had this problem described earlier
which does not let me complete this self documenting structure without
adding a thorough doc-string explaining that they still need to
implement one or two more methods.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: speed up a numpy code with huge array

2010-05-25 Thread draco parvus
On May 26, 7:05 am, Alexzive  wrote:
> Hello Pythonguys!
>
> is there a way to improve the performance of the attached code ? it
> takes about 5 h on a dual-core (using only one core) when len(V)
> ~1MIL. V is an array which is supposed to store all the volumes of
> tetrahedral elements of a grid whose coord. are stored in NN (accessed
> trough the list of tetraelements --> EL)
>
> Thanks in advance!
> Alex
>
> 
> print 'start ' + nameodb
> #path = '/windows/D/SIM-MM/3D/E_ortho/' + nameodb + '.odb'
> path = pt + nameodb + '.odb'
> odb = openOdb(path)
>
> N = odb.rootAssembly.instances['PART-1-1'].nodes
> if loadV==1:
>   pathV=pt+vtet
>   V=numpy.loadtxt(pathV)
>   VTOT = V[0]
>   L3 = V[1]
>   print 'using ' + vtet
> else:
>   NN=[]
>   B=[0,0,0,0]
>   for i in range(len(N)):
>         B[0] = N[i].label
>         B[1] = N[i].coordinates[0]
>         B[2] = N[i].coordinates[1]
>         B[3] = N[i].coordinates[2]
>         NN = append(NN,B)
>
>   NN=NN.reshape(-1,4)
>   EL = odb.rootAssembly.instances['PART-1-1'].elements
>
>   L1 = max(NN[:,1])-min(NN[:,1])
>   L2 = max(NN[:,2])-min(NN[:,2])
>   L3 = max(NN[:,3])-min(NN[:,3])
>   VTOT=L1*L2*L3
>   print 'VTOT: [mm³]' + str(VTOT)
>
>   V = array([])
>
>   print 'calculating new Vtet '
>   V = range(len(EL)+2)
>   V[0] = VTOT
>   V[1] = L3
>   for j in range(0,len(EL)):
>         Va = EL[j].connectivity[0]
>         Vb = EL[j].connectivity[1]
>         Vc = EL[j].connectivity[2]
>         Vd = EL[j].connectivity[3]
>         ix = where(NN[:,0] == Va)
>         Xa = NN[ix,1][0][0]
>         Ya = NN[ix,2][0][0]
>         Za = NN[ix,3][0][0]
>         ix = where(NN[:,0] == Vb)
>         Xb = NN[ix,1][0][0]
>         Yb = NN[ix,2][0][0]
>         Zb = NN[ix,3][0][0]
>         ix = where(NN[:,0] == Vc)
>         Xc = NN[ix,1][0][0]
>         Yc = NN[ix,2][0][0]
>         Zc = NN[ix,3][0][0]
>         ix = where(NN[:,0] == Vd)
>         Xd = NN[ix,1][0][0]
>         Yd = NN[ix,2][0][0]
>         Zd = NN[ix,3][0][0]
>         a =  [Xa,Ya,Za]
>         b =  [Xb,Yb,Zb]
>         c =  [Xc,Yc,Zc]
>         d =  [Xd,Yd,Zd]
>         aa = numpy.diff([b,a],axis=0)[0]
>         bb = numpy.diff([c,b],axis=0)[0]
>         cc = numpy.diff([d,c],axis=0)[0]
>         D=array([aa,bb,cc])
>         det=numpy.linalg.det(D)
>         V[j+2] = abs(det)/6
>   pathV = pt + vtet
>   savetxt(pathV, V, fmt='%.3e')
> ###

Main problem you've got is quadratic behaviour. For each vertex of
each of your million tets, you go through the entire node list to find
its coordinates. You should use a dict instead, such as:

allnodes = {}
for node in N:
  allnodes[node.label] = node.coordinates

And later, instead of using numpy.where, directly use:

Xa, Ya, Za = allnodes[Va] # with Va = EL[j].connectivity[0]
...

Should speed things up a bit. But manipulating odb files is never very
fast.

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


Re: speed up a numpy code with huge array

2010-05-25 Thread Stefan Behnel

Alexzive, 25.05.2010 21:05:

is there a way to improve the performance of the attached code ? it
takes about 5 h on a dual-core (using only one core) when len(V)
~1MIL. V is an array which is supposed to store all the volumes of
tetrahedral elements of a grid whose coord. are stored in NN (accessed
trough the list of tetraelements -->  EL)


Consider using Cython for your algorithm. It has direct support for NumPy 
arrays and translates to fast C code.


Stefan

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