Re: Request for feedback on API design

2010-12-09 Thread Steven D'Aprano
On Thu, 09 Dec 2010 18:48:10 -0600, Tim Chase wrote:

> On 12/09/2010 05:44 PM, Steven D'Aprano wrote:
>> (1) Multivariate statistics such as covariance have two obvious APIs:
>>
>>  A pass the X and Y values as two separate iterable arguments,
>>  e.g.:
>>cov([1, 2, 3], [4, 5, 6])
>>
>>  B pass the X and Y values as a single iterable of tuples, e.g.:
>>cov([(1, 4), (2, 5), (3, 6)]
>>
>> I currently support both APIs. Do people prefer one, or the other, or
>> both? If there is a clear preference for one over the other, I may drop
>> support for the other.
> 
> I'm partial to the "B" form (iterable of 2-tuples) -- it indicates that
> the two data-sets (x_n and y_n) should be of the same length and paired.
>  The "A" form leaves this less obvious that len(param1) should equal
> len(param2).


Thanks for the comments Tim. To answer your questions:


> I haven't poked at your code sufficiently to determine whether all the
> functions within can handle streamed data, or whether they keep the
> entire dataset internally,

Where possible, the functions don't keep the entire dataset internally. 
Some functions have to (e.g. order statistics need to see the entire data 
sequence at once), but the rest are capable of dealing with streamed data.

Also, there are a few functions such as standard deviation that have a 
single-pass algorithm, and a more accurate multiple-pass algorithm.


>> (2) Statistics text books often give formulae in terms of sums and
>> differences such as
>>
>> Sxx = n*Σ(x**2) - (Σx)**2
>>
>> There are quite a few of these: I count at least six common ones,
> 
> When you take this count, is it across multiple text-books, or are they
> common in just a small sampling of texts?  (I confess it's been a decade
> and a half since I last suffered a stats class)

I admit that I haven't done an exhaustive search of the literature, but 
it does seen quite common to extract common expressions from various 
stats formulae and give them names. The only use-case I can imagine for 
them is checking hand-calculations or doing schoolwork.


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


Re: printing error message from an Exception

2010-12-09 Thread Steven D'Aprano
On Thu, 09 Dec 2010 22:16:17 -0800, mark jason wrote:

> hi
> I was trying out some file operations and was trying to open a non
> existing file as below
> 
> def do_work(filename):
> try:
> f = open(filename,"r");
> print 'opened'
> except IOError, e:
> print 'failed',e.message
> finally:
> f.close()
> print 'closed'


The problem is, you try to close a file that not only hasn't been opened, 
but the name f isn't bound to a value:

>>> do_work('no such file')
failed
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 8, in do_work
UnboundLocalError: local variable 'f' referenced before assignment



> if __name__=='__main__':
> do_work("C:\code\misc.txt")   # there is no such file
> 
> I am getting an error and a warning
> 
> DeprecationWarning: BaseException.message has been deprecated as of
> Python 2.6
>   print 'failed',e.message
> 
> UnboundLocalError: local variable 'f' referenced before assignment
> 
> Is there a way to overcome the DeprecationWarning? I wanted to print the
> error message from the IOError.How do I do this? 

Generally, the best way to print error messages is to print the *entire* 
error message, including the traceback. You do that by just not catching 
the exception at all.

But for the times you do need to do something else with the exception, 
instead of exception.message, look at exception.args. This will be a 
tuple of one or more items, the first item should be the error message.


> Also ,what should I do about the UnboundLocalError?

Use finally for things which must be done regardless of whether or not 
the previous operation succeeded, not for things that should only be done 
if the previous operation succeeded but not if it failed.

def do_work(filename):
try:
f = open(filename,"r");
print 'opened'
except IOError, e:
# By the way, IOError is not the only exception you could see.
print 'failed', e.args
else:
f.close()
print 'closed'


Or, slightly more useful:

def do_work(filename):
s = ''
try:
f = open(filename,"r");
print 'opened'
except IOError, e:
# By the way, IOError is not the only exception you could see.
print 'failed', e.args
else:
try:
s = f.read()
finally:
f.close()
print 'closed'
print s



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


Re: dns library

2010-12-09 Thread Paulo da Silva
Em 10-12-2010 02:59, Jean-Paul Calderone escreveu:
> On Dec 9, 8:15 pm, Paulo da Silva 
> wrote:
>> Hi.
>>
>> Is there a python library/module to handle both the server and client
>> sides of dns protocol?
>>
>> I have googled for it but I only found client side ones (at least from
>> the superficial readings I did).
>>
>> Thanks.
> 
> Twisted Names is one such library:  
> http://twistedmatrix.com/trac/wiki/TwistedNames

I've just looked at its home page and it seems to be what I need.
Thank you very much.
-- 
http://mail.python.org/mailman/listinfo/python-list


printing error message from an Exception

2010-12-09 Thread mark jason
hi
I was trying out some file operations and was trying to open a non
existing file as below

def do_work(filename):
try:
f = open(filename,"r");
print 'opened'
except IOError, e:
print 'failed',e.message
finally:
f.close()
print 'closed'

if __name__=='__main__':
do_work("C:\code\misc.txt")   # there is no such file

I am getting an error and a warning

DeprecationWarning: BaseException.message has been deprecated as of
Python 2.6
  print 'failed',e.message

UnboundLocalError: local variable 'f' referenced before assignment

Is there a way to overcome the DeprecationWarning? I wanted to print
the error message from the IOError.How do I do this?
Also ,what should I do about the UnboundLocalError?

thanks and regards ,
mark
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Deprecation warnings (2.7 -> 3 )

2010-12-09 Thread Terry Reedy

On 12/9/2010 10:15 PM, rusi wrote:

In trying to get from 2.x to 3 Terry suggested I use 2.7 with
deprecation warnings


Heres the (first) set

DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__
in 3.x
DeprecationWarning: callable() not supported in 3.x; use isinstance(x,
collections.Callable)

Is there one place/site I can go to for understanding all these and
trying to clear them?


Not that I know of, but it would be a good idea. You could suggest on 
the tracker the addition of HOW TO Clear Deprecation Warnings, 2.7.
There would need to be a new one for each release, based on grepping the 
codebase.


--
Terry Jan Reedy

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


Re: little emacs lisp tutorial on turning a url into a link

2010-12-09 Thread small Pox
On Dec 9, 7:32 pm, small Pox  wrote:
> On Dec 4, 1:38 am, Xah Lee  wrote:
>
>
>
>
>
> > > On Dec 3, 8:20 pm, duckblue  wrote:
> > > > why is xah lee posting this information?
>
> > > > sites with more external links pointing to them are given a higher
> > > > ranking by search engines such as google. as a result they appear
> > > > closer to the top of the search engine results pages ('SERPs' in SEO
> > > > lingo).
> > > > xah's posting here is part of active an SEO campaign that he is
> > > > carrying out in order bring traffic to his site.- Hide quoted text -
>
> > On Dec 3, 9:16 pm, small Pox  wrote:
>
> > > Xah Lee writes good articles. She has a helpful attitude. Do you want
> > > her to become so financially dependent like that innocent looking
> > > rabbit teeth Adelyn Lee so she become a prostitute of Larry Ellis
> > > Islander who has gobbled up Sun, mysql, cray and so many software and
> > > hardware companies to make the largest and possibly going to be a most
> > > evil monopoly on earth ?
>
> > thanks.
>
> > interesting mention about Adelyn Lee.
>
> > I looked up,
>
> > 〈Woman Who Accused Oracle Chief Guilty of Perjury〉 January 29, 1997,
> > By Benjamin Pimentel, Chronicle Peninsula Bureau. SFGate Articles.
> > 〔http://articles.sfgate.com/1997-01-29/news/17741019_1_mr-ellison-adel...
> > 〕
>
> > Quote:
>
> > «A San Mateo woman accused of forging e-mail to sue Oracle Corp. was
> > found guilty yesterday of perjury and falsification of evidence.»
>
> > «Adelyn Lee, a 33-year-old former girlfriend of Oracle Chief Executive
> > Officer Larry Ellison, was convicted by a San Mateo County jury,
> > ending a Silicon Valley soap opera that revealed some of the inner
> > workings of the world's second-largest software company. »
>
> > «In 1995, Lee won a $100,000 settlement of a wrongful termination suit
> > in which she claimed that she was fired from her job as an executive
> > assistant after she refused to have sex with Ellison. »
>
> > interesting. Yeah, the 1990s, everything is sexual harassment.
>
> > it so happpens, i have a story to tell as well. I was officially
> > accused of sexual harassment in around 2000 while working at Netopia.
>
> I dont know about your story, but I know about many stories
>
> http://www.orafraud.info/terminator_4.0.html
>
> To dig them you have to search hard enough.
>
> The one you found was skewed by SEO type work. The khazars are very
> tight-knit.
>
> Also rasputin has lots of money to get people to write fiction on him
> and his current wife is a fiction writer as well. The Kourts are
> cangaroo. Lies are as common as roman polansky fleed to europe after
> raping a 13years old.
>
> Your attempt to flatter is amateurish. It shows through that you are
> trying to flatter the money.
>
> Dont be cannibalizing that innocent girl. He baited her by a car which
> is worthless. Her virginity was stolen - priceless. She expected to be
> married and everyone knows that this is what any woman's price of sex
> is.
>
> Like your own mother.
>
> The guy is from anonymous father so he tries to put every decent woman
> down ... perhaps.
>
> He fired her to escape her vengeance.
>
> His sycophants then altered database records.
>
> She could not fight in the court. American courts are filled with
> false lawsuits.
>
> They did this to germany and now doing to USA.
>
> Orwell understood them one century before us. In 1984 he describes
> them as the guy O’Brien who "treated" Winston. You should thoroughly
> read the protocols of the learned elders of zion at the atzlan site
> and archive all of their versions and commentaries.
>
> Flattery wont get you anywhere  ... better apply your brain power to
> create a rival to database before they gobble up all the hardware
> companies to make computers with builtin trojans in hardware like the
> telescreen of 1984.
>
>
>
> > The whole case is ridiculous. The woman who accused me, was
> > romantically interested in me. She's got some personal psychological
> > problems. We both are sys admins (but i also do dev). She lives and
> > work at the Kansas branch, while i work in California. Once or twice a
> > year, the company has her flew over for business, typically lasting
> > just a day. I'm not her superior or vice versa. Our relationship
> > started when she started to IM me and got me to use AOL.  The AOL chat
> > is kinda used for business discussions as well, since it's just
> > convenient, and apparantly it became popular in the company.
> > (remember, this is 1999.) When she came over, i think the second time,
> > then later, she filed a sexual harassment to Netopia. (i didn't even
> > know before) We did not sleep together. The closest physical contact
> > might be holding hands, which, i don't remember we actually did. All i
> > know after the whole thing is that she's got some kinda love hang-
> > over.
>
> > At the end, they (the human resource woman who handles this) ask me to
> > sign a paper, which, if i recall correctly, basica

Re: little emacs lisp tutorial on turning a url into a link

2010-12-09 Thread small Pox
On Dec 9, 7:32 pm, small Pox  wrote:
> On Dec 4, 1:38 am, Xah Lee  wrote:
>
>
>
>
>
> > > On Dec 3, 8:20 pm, duckblue  wrote:
> > > > why is xah lee posting this information?
>
> > > > sites with more external links pointing to them are given a higher
> > > > ranking by search engines such as google. as a result they appear
> > > > closer to the top of the search engine results pages ('SERPs' in SEO
> > > > lingo).
> > > > xah's posting here is part of active an SEO campaign that he is
> > > > carrying out in order bring traffic to his site.- Hide quoted text -
>
> > On Dec 3, 9:16 pm, small Pox  wrote:
>
> > > Xah Lee writes good articles. She has a helpful attitude. Do you want
> > > her to become so financially dependent like that innocent looking
> > > rabbit teeth Adelyn Lee so she become a prostitute of Larry Ellis
> > > Islander who has gobbled up Sun, mysql, cray and so many software and
> > > hardware companies to make the largest and possibly going to be a most
> > > evil monopoly on earth ?
>
> > thanks.
>
> > interesting mention about Adelyn Lee.
>
> > I looked up,
>
> > 〈Woman Who Accused Oracle Chief Guilty of Perjury〉 January 29, 1997,
> > By Benjamin Pimentel, Chronicle Peninsula Bureau. SFGate Articles.
> > 〔http://articles.sfgate.com/1997-01-29/news/17741019_1_mr-ellison-adel...
> > 〕
>
> > Quote:
>
> > «A San Mateo woman accused of forging e-mail to sue Oracle Corp. was
> > found guilty yesterday of perjury and falsification of evidence.»
>
> > «Adelyn Lee, a 33-year-old former girlfriend of Oracle Chief Executive
> > Officer Larry Ellison, was convicted by a San Mateo County jury,
> > ending a Silicon Valley soap opera that revealed some of the inner
> > workings of the world's second-largest software company. »
>
> > «In 1995, Lee won a $100,000 settlement of a wrongful termination suit
> > in which she claimed that she was fired from her job as an executive
> > assistant after she refused to have sex with Ellison. »
>
> > interesting. Yeah, the 1990s, everything is sexual harassment.
>
> > it so happpens, i have a story to tell as well. I was officially
> > accused of sexual harassment in around 2000 while working at Netopia.
>
> I dont know about your story, but I know about many stories
>
> http://www.orafraud.info/terminator_4.0.html
>
> To dig them you have to search hard enough.
>
> The one you found was skewed by SEO type work. The khazars are very
> tight-knit.
>
> Also rasputin has lots of money to get people to write fiction on him
> and his current wife is a fiction writer as well. The Kourts are
> cangaroo. Lies are as common as roman polansky fleed to europe after
> raping a 13years old.
>
> Your attempt to flatter is amateurish. It shows through that you are
> trying to flatter the money.
>
> Dont be cannibalizing that innocent girl. He baited her by a car which
> is worthless. Her virginity was stolen - priceless. She expected to be
> married and everyone knows that this is what any woman's price of sex
> is.
>
> Like your own mother.
>
> The guy is from anonymous father so he tries to put every decent woman
> down ... perhaps.
>
> He fired her to escape her vengeance.
>
> His sycophants then altered database records.
>
> She could not fight in the court. American courts are filled with
> false lawsuits.
>
> They did this to germany and now doing to USA.
>
> Orwell understood them one century before us. In 1984 he describes
> them as the guy O’Brien who "treated" Winston. You should thoroughly
> read the protocols of the learned elders of zion at the atzlan site
> and archive all of their versions and commentaries.
>
> Flattery wont get you anywhere  ... better apply your brain power to
> create a rival to database before they gobble up all the hardware
> companies to make computers with builtin trojans in hardware like the
> telescreen of 1984.
>
>
>
> > The whole case is ridiculous. The woman who accused me, was
> > romantically interested in me. She's got some personal psychological
> > problems. We both are sys admins (but i also do dev). She lives and
> > work at the Kansas branch, while i work in California. Once or twice a
> > year, the company has her flew over for business, typically lasting
> > just a day. I'm not her superior or vice versa. Our relationship
> > started when she started to IM me and got me to use AOL.  The AOL chat
> > is kinda used for business discussions as well, since it's just
> > convenient, and apparantly it became popular in the company.
> > (remember, this is 1999.) When she came over, i think the second time,
> > then later, she filed a sexual harassment to Netopia. (i didn't even
> > know before) We did not sleep together. The closest physical contact
> > might be holding hands, which, i don't remember we actually did. All i
> > know after the whole thing is that she's got some kinda love hang-
> > over.
>
> > At the end, they (the human resource woman who handles this) ask me to
> > sign a paper, which, if i recall correctly, basica

Re: little emacs lisp tutorial on turning a url into a link

2010-12-09 Thread small Pox
On Dec 4, 1:38 am, Xah Lee  wrote:
> > On Dec 3, 8:20 pm, duckblue  wrote:
> > > why is xah lee posting this information?
>
> > > sites with more external links pointing to them are given a higher
> > > ranking by search engines such as google. as a result they appear
> > > closer to the top of the search engine results pages ('SERPs' in SEO
> > > lingo).
> > > xah's posting here is part of active an SEO campaign that he is
> > > carrying out in order bring traffic to his site.- Hide quoted text -
>
> On Dec 3, 9:16 pm, small Pox  wrote:
>
> > Xah Lee writes good articles. She has a helpful attitude. Do you want
> > her to become so financially dependent like that innocent looking
> > rabbit teeth Adelyn Lee so she become a prostitute of Larry Ellis
> > Islander who has gobbled up Sun, mysql, cray and so many software and
> > hardware companies to make the largest and possibly going to be a most
> > evil monopoly on earth ?
>
> thanks.
>
> interesting mention about Adelyn Lee.
>
> I looked up,
>
> 〈Woman Who Accused Oracle Chief Guilty of Perjury〉 January 29, 1997,
> By Benjamin Pimentel, Chronicle Peninsula Bureau. SFGate Articles.
> 〔http://articles.sfgate.com/1997-01-29/news/17741019_1_mr-ellison-adel...
> 〕
>
> Quote:
>
> «A San Mateo woman accused of forging e-mail to sue Oracle Corp. was
> found guilty yesterday of perjury and falsification of evidence.»
>
> «Adelyn Lee, a 33-year-old former girlfriend of Oracle Chief Executive
> Officer Larry Ellison, was convicted by a San Mateo County jury,
> ending a Silicon Valley soap opera that revealed some of the inner
> workings of the world's second-largest software company. »
>
> «In 1995, Lee won a $100,000 settlement of a wrongful termination suit
> in which she claimed that she was fired from her job as an executive
> assistant after she refused to have sex with Ellison. »
>
> interesting. Yeah, the 1990s, everything is sexual harassment.
>
> it so happpens, i have a story to tell as well. I was officially
> accused of sexual harassment in around 2000 while working at Netopia.

I dont know about your story, but I know about many stories

http://www.orafraud.info/terminator_4.0.html

To dig them you have to search hard enough.

The one you found was skewed by SEO type work. The khazars are very
tight-knit.

Also rasputin has lots of money to get people to write fiction on him
and his current wife is a fiction writer as well. The Kourts are
cangaroo. Lies are as common as roman polansky fleed to europe after
raping a 13years old.

Your attempt to flatter is amateurish. It shows through that you are
trying to flatter the money.

Dont be cannibalizing that innocent girl. He baited her by a car which
is worthless. Her virginity was stolen - priceless. She expected to be
married and everyone knows that this is what any woman's price of sex
is.

Like your own mother.

The guy is from anonymous father so he tries to put every decent woman
down ... perhaps.

He fired her to escape her vengeance.

His sycophants then altered database records.

She could not fight in the court. American courts are filled with
false lawsuits.

They did this to germany and now doing to USA.

Orwell understood them one century before us. In 1984 he describes
them as the guy O’Brien who "treated" Winston. You should thoroughly
read the protocols of the learned elders of zion at the atzlan site
and archive all of their versions and commentaries.

Flattery wont get you anywhere  ... better apply your brain power to
create a rival to database before they gobble up all the hardware
companies to make computers with builtin trojans in hardware like the
telescreen of 1984.

> The whole case is ridiculous. The woman who accused me, was
> romantically interested in me. She's got some personal psychological
> problems. We both are sys admins (but i also do dev). She lives and
> work at the Kansas branch, while i work in California. Once or twice a
> year, the company has her flew over for business, typically lasting
> just a day. I'm not her superior or vice versa. Our relationship
> started when she started to IM me and got me to use AOL.  The AOL chat
> is kinda used for business discussions as well, since it's just
> convenient, and apparantly it became popular in the company.
> (remember, this is 1999.) When she came over, i think the second time,
> then later, she filed a sexual harassment to Netopia. (i didn't even
> know before) We did not sleep together. The closest physical contact
> might be holding hands, which, i don't remember we actually did. All i
> know after the whole thing is that she's got some kinda love hang-
> over.
>
> At the end, they (the human resource woman who handles this) ask me to
> sign a paper, which, if i recall correctly, basically want me to admit
> some wrong doing or something like that. I do not agree to it, i
> refused to sign. And that basically is the end of it. She quit or was
> fired sometimes later on (don't think it has anything to do with
> this).

Deprecation warnings (2.7 -> 3 )

2010-12-09 Thread rusi
In trying to get from 2.x to 3 Terry suggested I use 2.7 with
deprecation warnings


Heres the (first) set

DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__
in 3.x
DeprecationWarning: callable() not supported in 3.x; use isinstance(x,
collections.Callable)

Is there one place/site I can go to for understanding all these and
trying to clear them?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dns library

2010-12-09 Thread Jean-Paul Calderone
On Dec 9, 8:15 pm, Paulo da Silva 
wrote:
> Hi.
>
> Is there a python library/module to handle both the server and client
> sides of dns protocol?
>
> I have googled for it but I only found client side ones (at least from
> the superficial readings I did).
>
> Thanks.

Twisted Names is one such library:  
http://twistedmatrix.com/trac/wiki/TwistedNames
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Proposed changes to logging defaults

2010-12-09 Thread Vinay Sajip
On Dec 10, 12:48 am, Ethan Furman  wrote:
>
> I like the changes proposed.
>
> Question about the "handler of last resort":  is there only one of them,
> or will each library have its own so it can decide what the minimum
> severity should be for itself?

Libraries decide their severities differently, by setting a level on
their top level logger. There's only one handler of last resort (else
it wouldn't be a last resort). Generally, application developers
determine the level for each logger they're interested; if no explicit
levels are set, the default is the level of the root logger (WARNING
by default).

Thanks for the feedback,

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


dns library

2010-12-09 Thread Paulo da Silva
Hi.

Is there a python library/module to handle both the server and client
sides of dns protocol?

I have googled for it but I only found client side ones (at least from
the superficial readings I did).

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


Re: win32 design pattern: COM localserver?

2010-12-09 Thread Mark Hammond
If you are implementing a COM object using win32com, then Python will 
never be unloaded from the host process, which works in your favour. 
Just have the COM object use a thread and a queue for this processing. 
The 'report' method would just stick the params and filenames in the 
queue and return immediately - your thread should stay alive and working 
away so long as the host process remains alive.  You probably need to 
deal with the face the thread will be unexpectedly terminated when the 
host process terminates or add a new method designed explicitly to block 
the host process until everything is complete - the host program would 
then call this method just before it terminates.


Also note there is a python-wi...@python.org mailing list where you 
might get better or more advice...


Cheers,

Mark


On 8/12/2010 8:03 PM, kirby.ur...@gmail.com wrote:

Greetings gurus.

I'm faced with the challenge of having a single-threaded proprietary
Win32
language wanting to do multiple calls against a Python COM object.

Something like...

loObj = CREATEOBJECT("map_maker")
loObj.report( params, filename)

do while .True.
   yadda yadda
enddo

RETURN

I.e. the client program continues execution while loObj churns away
somewhere doing work in Python, say accessing a MySQL database
and building a map, embedding it in a PDF.

Am I right that the COM object will need to "serve forever" i.e. be
built around some non-terminating loop?  Will the client's call then
spawn a process or thread that continues until finished?

All it has to do is leave a file on disk somewhere, then die.  But
the client can't be kept on the hook until that's all done.

I've had good luck doing an InProcess COM object the generates
a PDF from ReportLab.  But this "stay alive while returning control
to the client" challenge looks like it might be a job for sockets?

Gee I hope not.

Quick links to favorite blog articles will give me a sense of the
ballpark...  Any clues welcome.  Yes, I have the Win32 book from
O'Reilly.

Kirby

PS:  my thanks to Ethan Furman for performing maintenance and
upgrades on his dbf module on PyPI.  The FoxPro gods thank you.
http://pypi.python.org/pypi/dbf/0.88.16

PPS:  some thoughts about IronPython filed here, after trying to
catch up some, sorry about my formatting, here too.
http://mail.python.org/pipermail/edu-sig/2010-December/010138.html



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


Re: Request for feedback on API design

2010-12-09 Thread Tim Chase

On 12/09/2010 05:44 PM, Steven D'Aprano wrote:

(1) Multivariate statistics such as covariance have two obvious APIs:

 A pass the X and Y values as two separate iterable arguments, e.g.:
   cov([1, 2, 3], [4, 5, 6])

 B pass the X and Y values as a single iterable of tuples, e.g.:
   cov([(1, 4), (2, 5), (3, 6)]

I currently support both APIs. Do people prefer one, or the other, or
both? If there is a clear preference for one over the other, I may drop
support for the other.


I'm partial to the "B" form (iterable of 2-tuples) -- it 
indicates that the two data-sets (x_n and y_n) should be of the 
same length and paired.  The "A" form leaves this less obvious 
that len(param1) should equal len(param2).


I haven't poked at your code sufficiently to determine whether 
all the functions within can handle streamed data, or whether 
they keep the entire dataset internally, but handing off an 
iterable-of-pairs tends to be a little more straight-forward:


  cov(humongous_dataset_iter)

or

  cov(izip(humongous_dataset_iter1, humongous_dataset_iter2))

The "A" form makes doing this a little less obvious than the "B" 
form.



(2) Statistics text books often give formulae in terms of sums and
differences such as

Sxx = n*Σ(x**2) - (Σx)**2

There are quite a few of these: I count at least six common ones,


When you take this count, is it across multiple text-books, or 
are they common in just a small sampling of texts?  (I confess 
it's been a decade and a half since I last suffered a stats class)



all closely related and confusing named:

Sxx, Syy, Sxy, SSx, SSy, SPxy

(the x and y should all be subscript).

Are they useful, or would they just add unnecessary complexity?


I think it depends on your audience:  amateur statisticians or 
pros?  I suspect that pros wouldn't blink at the distinctions 
while weekenders like myself would get a little bleary-eyed 
without at least a module docstring to clearly spell out the 
distinctions and the forumlae used for determining them.


Just my from-the-hip thoughts for whatever little they may be worth.

-tkc



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


Re: Proposed changes to logging defaults

2010-12-09 Thread Ethan Furman

Vinay Sajip wrote:

Some changes are being proposed to how logging works in default
configurations.


I like the changes proposed.

Question about the "handler of last resort":  is there only one of them, 
or will each library have its own so it can decide what the minimum 
severity should be for itself?


(My apologies if this question only reveals my own ignorance.)

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


Proposed changes to logging defaults

2010-12-09 Thread Vinay Sajip
Some changes are being proposed to how logging works in default
configurations.

Briefly - when a logging event occurs which needs to be output to some
log, the behaviour of the logging package when no explicit logging
configuration is provided will change, most likely to log those events
to sys.stderr with a default format.

Since this proposed change to behaviour is backwards-incompatible (and
scheduled to come in to Python 3.2 - earlier Pythons, including 2.X,
are unaffected), you may be interested in seeing if the changes affect
you. More details are available here:

http://plumberjack.blogspot.com/2010/12/proposed-changes-to-logging-defaults.html

Please feel free to add comments to the linked blog post.

Regards,

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


Re: ***locale.Error: unsupported locale setting***

2010-12-09 Thread Vlastimil Brom
2010/12/9 Anurag Chourasia :
> Hi All,
> When i try to set a locale manually, i get this error.
 import locale
 locale.setlocale(locale.LC_ALL, 'es_cl.iso88591')
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/local/lib/python2.7/locale.py", line 531, in setlocale
>     return _setlocale(category, locale)
> locale.Error: unsupported locale setting
> On my OS, when i run the locale -a command, i get this output
> -
> locale -a
> C
> POSIX
> en_US
> en_US.8859-15
> en_US.ISO8859-1
> -
> Does this means that on my machine, Python will be able to make use of above
> listed locales?
> If yes then how can i possibly use the locale.setformat (or anything else
> for that matter) to group numbers using '.' as the thousands separator?
> If i use the locale en_US then ',' is the thousands separator.
 import locale
 locale.setlocale(locale.LC_ALL, 'en_US')
> 'en_US'
 locale.format("%d", 1255000, grouping=True)
> '1,255,000'
> Regards,
> Anurag
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
Hi,
I am not sure, it helps in your case, but the simple locale aliases
(like "Spanish") seem to work for me (py 2.7.1, win 7)

>>> locale.getlocale()
('Czech_Czech Republic', '1250')
>>> locale.localeconv()['thousands_sep']
'\xa0'
>>> locale.setlocale(locale.LC_ALL, "Spanish")
'Spanish_Spain.1252'
>>> locale.localeconv()['thousands_sep']
'.'
>>> locale.format("%d", 1255000, grouping=True)
'1.255.000'
>>>

hth,
  vbr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Reference counting problems?

2010-12-09 Thread MRAB

On 09/12/2010 20:23, Eric Frederich wrote:

I am attempting to automate the building of binding for a 3rd party library.
The functions I'm wrapping all return an integer of whether they
failed and output are passed as pointers.
There can be multiple return values.
So the code that I generate has a PyObject* called python__return_val
that I use for returning.
In the 'wrapped_foo' function below you see I build the return value
with Py_BuildValue and "OO" as the format.
For every output I have I do a C to Python conversion and add another
'O' to the format.
What I'm wondering is if I can use the same logic when wrapping
functions that only return one value like the wrapped_bar function
below.

So for multiples, I wind up doing this which is fine.

 python__x = Py_BuildValue("s", x)


The object at python__x has a refcount of 1.


 python__y = Py_BuildValue("s", y)


The object at python__y has a refcount of 1.


 python__return_val = Py_BuildValue("OO", python__x, python__y);


The object at python__return_val (a tuple) has a refcount of 1. This
object refers to the objects at python__x and python__y, so both of
their refcounts will have been incremented to 2. You will need to
DECREF the objects at python__x and python__y before the C variables
python__x and python__y go out of scope.


But for single returns I do something like this
I realize that the 2 lines below are pointless, but are they causing a
memory leak or problems with reference counting?

 python__x = Py_BuildValue("s", x)


The object at python__x has a refcount of 1.


 python__return_val = Py_BuildValue("O", python__x);


In this case Py_BuildValue returns its argument python__x, but will
have incremented its refcount to 2. This means that you still need to
DECREF the object at python__x before the C variable python__x goes out
of scope.

This is probably just for consistency, because it's easier to remember
that /every time/ you pass an object to Py_BuildValue its refcount will
be incremented, than if it was sometimes yes, sometimes no.



Are python__x and python__return_val the same object, a copy of the object?
Would python__x ever get garbage collected?
Should my code generator detect when there is only one output and not
go through the extra step?


[snip]
--
http://mail.python.org/mailman/listinfo/python-list


Request for feedback on API design

2010-12-09 Thread Steven D'Aprano
I am soliciting feedback regarding the API of my statistics module:

http://code.google.com/p/pycalcstats/


Specifically the following couple of issues:

(1) Multivariate statistics such as covariance have two obvious APIs:

A pass the X and Y values as two separate iterable arguments, e.g.: 
  cov([1, 2, 3], [4, 5, 6])

B pass the X and Y values as a single iterable of tuples, e.g.:
  cov([(1, 4), (2, 5), (3, 6)]

I currently support both APIs. Do people prefer one, or the other, or 
both? If there is a clear preference for one over the other, I may drop 
support for the other.


(2) Statistics text books often give formulae in terms of sums and 
differences such as

Sxx = n*Σ(x**2) - (Σx)**2

There are quite a few of these: I count at least six common ones, all 
closely related and confusing named:

Sxx, Syy, Sxy, SSx, SSy, SPxy

(the x and y should all be subscript).

Are they useful, or would they just add unnecessary complexity? Would 
people would like to see these included in the package?



Thank you for your feedback.


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


Re: Comparisons of incompatible types

2010-12-09 Thread Steven D'Aprano
On Thu, 09 Dec 2010 09:34:19 -0800, John Nagle wrote:

> (The best coverage of this whole topic was the Apple Numerics Manual
> for the original Mac.  Apple hired the floating point expert from
> Berkeley to get this right. Then Apple went from the M68xxx series to
> the IBM PowerPC, and 80-bit floats to 64-bit floats, breaking all the
> engineering applications, most of which were never ported to the
> PowerPC.)

I second John's recommendation re the Apple Numerics Manual. Even if the 
Apple specific stuff is obsolete, it's a great resource for understanding 
floating point issues.


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


Re: Comparisons of incompatible types

2010-12-09 Thread Steven D'Aprano
On Thu, 09 Dec 2010 12:21:45 +, Mark Wooding wrote:

> John Nagle  writes:

>> "sort" has failed because it assumes that a < b and b < c implies a <
>> c. But that's not a valid assumption here.
>>
>> It's not good to break trichotomy.
> 
> You're confused.  The property
> 
> a < b and b < c => a < c
> 
> is called `transitivity'.  

Yes, but I believe that John is referring to the trichotomy (like a 
dichotomy, only there are three options instead of two) that exactly one 
of these relations are true:

a < b
a == b
a > b

It is true for real numbers, but not for IEEE floats, since none of the 
three are true if either a or b are a NAN. (Non-IEEE floats could do 
anything...)


[...]
>   2. Totality: a <= b or b <= a
> 
> The above list sorting goes wrong because the `float' ordering isn't
> total.  In particular, x  NaN!).

I believe this is equivalent to trichotomy.


> So, your last remark is in the right direction (though strict trichotomy
> is unnecessary, as I've mentioned), but apparently only by accident
> since the preceding discussion is completely wrong.

"Completely" is surely a tad strong -- John might not be using the exact 
same terminology as you, but he's clearly talking about the equivalent 
concepts. He wants and expects all data types to either meet a total 
order, or raise an exception to any of the < > <= and >= operators.


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


Re: 64 bit memory usage

2010-12-09 Thread John Nagle

On 12/8/2010 10:42 PM, Dennis Lee Bieber wrote:

On Wed, 8 Dec 2010 14:44:30 +, Rob Randall
declaimed the following in gmane.comp.python.general:


I am trying to understand how much memory is available to a 64 bit python
process running under Windows XP 64 bit.

When I run tests just creating a series of large dictionaries containing
string keys and float values I do not seem to be able to grow the process
beyond the amount of RAM present.


   If you get to the point where you need multi-gigabyte Python
dictionaries, you may be using the wrong tool for the job.
If it's simply that you need to manage a large amount of data,
that's what databases are for.

   If this is some super high performance application that needs to 
keep a big database in memory for performance reasons, CPython

is probably too slow.  For that, something like Google's BigTable
may be more appropriate, and will scale to terabytes if necessary.

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


***locale.Error: unsupported locale setting***

2010-12-09 Thread Anurag Chourasia
Hi All,

When i try to set a locale manually, i get this error.

>>> import locale
>>> locale.setlocale(locale.LC_ALL, 'es_cl.iso88591')
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python2.7/locale.py", line 531, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting

On my OS, when i run the locale -a command, i get this output
-
*locale -a*
C
POSIX
en_US
en_US.8859-15
en_US.ISO8859-1
-
Does this means that on my machine, Python will be able to make use of above
listed locales?

*If yes then how can i possibly use the locale.setformat (or anything else
for that matter) to group numbers using '.' as the thousands separator?*

If i use the locale en_US then ',' is the thousands separator.

>>> import locale
>>> locale.setlocale(locale.LC_ALL, 'en_US')
'en_US'
>>> locale.format("%d", 1255000, grouping=True)
'1,255,000'

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


Re: completely implicit interpolation based on a frame object (nn)

2010-12-09 Thread Edward Peschko
>> a bit closer here, but I'm not sure if they are
>> workable (or usable) with 2.5... which is where I need to work.
>>
>> Ed
>
> One of the solutions from here might work for you:
>
> http://wiki.python.org/moin/Templating
>

Ok, cool. A couple of followups - I'd be interested in knowing which
of the solutions listed there was:

1. lightweight
2. usable with 2.5 (and if possible 2.3,2.2, and 2.1)
3. able to do inplace expansion of arrays and/or hashes, using
arbitrary functions, in a simplistic way (perhaps like formats and the
{var!func} syntax)

I'll read up on them, but as it is with perl, you can spend a lot of
time fiddling around with a module to find out that the implementation
doesn't support the featureset that you are looking for, or otherwise
is just plain junk, so pointers are definitely welcome on which one to
use.

--

Anyways, the problem isn't completely solved here. Since it is a
free-flowing string that needs to be interpolated, there needs to be
some way of picking out the identifiers that are to be evaluated and
turning them into a template. In the following code:

person="mary"
print "then along came a person named ", person

this has to evaluate to

print "then along came a person named ", mary

There's also subtleties here - if foo.somesuch is an attribute, there
is no chance of a side effect, but if foo.somesuch is a property, then
it could inadvertently cause side effects, and only one side effect
can totally ruin your day (that was the bulk of the complexity in the
perl version of this, ensuring no side effects in the expanded vars)

Likewise, if a line of code spans multiple lines, you may have
identifiers that span these multiple lines which means you may miss
some substitutions.

So, again, I'm interested in ways of getting around these problems. In
perl its very easy to do this because of sigils, would very much like
to know how to do the same thing in python.

thanks much,

Ed

(ps - this is what I've got so far, which is basically cobbled
together from stuff on stackoverflow. Works ok, but lines #15-#16
AFAICT are the one that needs to be bulletproofed:

1   import sys
2   import linecache
3   import random
4
5   def traceit(frame, event, arg):
6   if event == "line":
7   lineno = frame.f_lineno
8   filename = frame.f_globals["__file__"]
9   if filename == "":
10filename = "traceit.py"
11if (filename.endswith(".pyc") or
12filename.endswith(".pyo")):
13filename = filename[:-1]
14name = frame.f_globals["__name__"]
15line = linecache.getline(filename, lineno)
16print "%s:%s:%s: %s" % (name,
lineno,frame.f_code.co_name,line.rstrip())
17return traceit
18
20 sys.settrace(traceit)
21 main()

)

(
pps - is there a collection of tracers somewhere? This seems
definitely the thing that you'd want to collect in a library
somewhere, and switch tracers as you see fit depending on what you are
looking for..
)
-- 
http://mail.python.org/mailman/listinfo/python-list


Added Python, WSGI to XAMPP

2010-12-09 Thread Gerry Reno
If you have any need of a portable LAMP stack, I just finished writing
some How-To's for getting Python, VirtualEnv and WSGI frameworks running
with XAMPP:

How-To: Add VirtualEnv and Pylons (WSGI framework) to XAMPP


How-To: Add VirtualEnv and Django (WSGI framework) to XAMPP


How-To: Add Python and mod_wsgi to XAMPP



-Gerry

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


Reference counting problems?

2010-12-09 Thread Eric Frederich
I am attempting to automate the building of binding for a 3rd party library.
The functions I'm wrapping all return an integer of whether they
failed and output are passed as pointers.
There can be multiple return values.
So the code that I generate has a PyObject* called python__return_val
that I use for returning.
In the 'wrapped_foo' function below you see I build the return value
with Py_BuildValue and "OO" as the format.
For every output I have I do a C to Python conversion and add another
'O' to the format.
What I'm wondering is if I can use the same logic when wrapping
functions that only return one value like the wrapped_bar function
below.

So for multiples, I wind up doing this which is fine.

python__x = Py_BuildValue("s", x)
python__y = Py_BuildValue("s", y)
python__return_val = Py_BuildValue("OO", python__x, python__y);

But for single returns I do something like this
I realize that the 2 lines below are pointless, but are they causing a
memory leak or problems with reference counting?

python__x = Py_BuildValue("s", x)
python__return_val = Py_BuildValue("O", python__x);


Are python__x and python__return_val the same object, a copy of the object?
Would python__x ever get garbage collected?
Should my code generator detect when there is only one output and not
go through the extra step?

Thanks,
~Eric



static PyObject *
wrapped_foo(PyObject *self, PyObject *args)
{
int wrapp_fail;
// C types
int  x;
const char*  some_str;
int* y;
char**   abc;

// Python types
PyObject*python__return_val;
PyObject*python__y;
PyObject*python__abc;

// Get Python args
if (!PyArg_ParseTuple(args, "is", &x, &some_str))
return NULL;

// Wrapped Call
wrapp_fail = foo(x, some_str, &y, &abc);
if(wrapp_fail != 0){
return NULL;
}

// Convert output to Python types
python__y = Py_BuildValue("i", y)
python__abc = Py_BuildValue("s", abc)


// Build Python return value
python__return_val = Py_BuildValue("OO", python__y, python__abc);

// Memory free's
MEM_free(abc)

return python__return_val;
}


static PyObject *
wrapped_bar(PyObject *self, PyObject *args)
{
int wrapp_fail;
// C types
int  a;
const char*  b;
char**   c;

// Python types
PyObject*python__return_val;
PyObject*python__c;

// Get Python args
if (!PyArg_ParseTuple(args, "is", &a, &b))
return NULL;

// Wrapped Call
wrapp_fail = bar(a, b, &c);
if(wrapp_fail != 0){
return NULL;
}

// Convert output to Python types
python__c = Py_BuildValue("s", c)


// Build Python return value
python__return_val = Py_BuildValue("O", python__c);

// Memory free's
MEM_free(c)

return python__return_val;
}
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 64 bit memory usage

2010-12-09 Thread Antoine Pitrou
On Thu, 9 Dec 2010 17:18:58 +
Rob Randall  wrote:
> Basically the process runs at around 1% and it never seems to grow in size
> again.
> When running the C++ with python app the process slows when a new 'page' is
> required but then goes back to 'full' speed. It does this until basically
> all the virtual memory is used.

Intuitively, Benjamin Kaplan had the right answer: Python will
periodically walk the heap of objects to look for dead reference cycles
to collect; if your working set is larger than the available RAM, then
this will thrash the pagefile to death.

So try gc.disable() before doing your tests.

I would stress that, of course, you will still have performance problems
as soon as you start using all those areas you are allocating. And if
you don't use them, I guess there's no point allocating them either. So
I don't know what exactly you're trying to do (is this an actual
application? or just some random test you're doing?), but relying on
the pagefile to have more available memory than the system RAM is a
very bad idea IMO.

Regards

Antoine.


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


Re: 64 bit memory usage

2010-12-09 Thread Rob Randall
I will give it a try with the garbage collector disabled.

On 9 December 2010 17:29, Benjamin Kaplan  wrote:

> On Thursday, December 9, 2010, Rob Randall  wrote:
> > But the C++ program using up memory does not slow up.
> > It has gone to 40GB without much trouble.
> >
>
> Your C++ program probably doesn't have a garbage collector traversing
> the entire allocated memory looking for reference cycles.
>
> > Does anyone have a 64 bit python application that uses more the 2GB?
> >
> > On 9 December 2010 16:54, Antoine Pitrou  wrote:
> > On Wed, 8 Dec 2010 14:44:30 +
> > Rob Randall  wrote:
> >> I am trying to understand how much memory is available to a 64 bit
> python
> >> process running under Windows XP 64 bit.
> >>
> >> When I run tests just creating a series of large dictionaries containing
> >> string keys and float values I do not seem to be able to grow the
> process
> >> beyond the amount of RAM present.
> >>
> >> For example, on a box with 2GB RAM and 3 GB pagefile the process stalls
> at
> >> around 2GB.
> >>
> >> On another machine with 16GB RAM and 24GB pagefile the process stalls at
> >> 16GB.
> >
> > How is it surprising? When you go past the available RAM, your process
> > starts swapping and everything becomes incredibly slower.
> >
> > Regards
> >
> > Antoine.
> >
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> >
> >
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Condition signals and restarts, resumable exceptions (was: Comparison with False - something I don't understand)

2010-12-09 Thread Teemu Likonen
* 2010-12-06 00:14 (-0800), Paul Rubin wrote:

> You know, I've heard the story from language designers several times
> over, that they tried putting resumable exceptions into their
> languages and it turned out to be a big mess, so they went to
> termination exceptions that fixed the issue. Are there any languages
> out there with resumable exceptions?

As some people have pointer out Common Lisp is one of those languages. I
don't know anything about language design, I'm just a hobbyist
programmer, but I think Common Lisp's condition system and its restarts
are straight-forward and easy to understand from programmer's point of
view.

Here's the relevant chapter in Peter Seibel's Practical Common Lisp:

http://www.gigamonkeys.com/book/beyond-exception-handling-conditions-and-restarts.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trace cmd line args

2010-12-09 Thread rusi
On Dec 9, 10:37 pm, rusi  wrote:
> On Dec 9, 9:03 pm, Terry Reedy  wrote:
>
>
>
> > On 12/9/2010 7:12 AM, rusi wrote:
>
> > > On Dec 9, 1:39 pm, Terry Reedy  wrote:
> > >> On 12/9/2010 1:10 AM, rusi wrote:
>
> > >>> I am unable to get trace to not trace system modules.
>
> > >> Try it with 3.2b1, just released. Multiple bugs were fixed in trace.
> > >> Some fixes might also be in recent 2.7.1 and 3.1.3. Not sure.
>
> > >> --
> > >> Terry Jan Reedy
>
> > > I am doing this to port a 2.x app to 3 which is giving me a hell of a
> > > time! :-;
>
> > I would get it to run on 2.7 first, with out getting any
> > DeprecationWarnings when they are turned on. They are off by default and
> > I am not sure how to turn on but presume the warnings module doc says how.
>
> > --
> > Terry Jan Reedy
>
> This is a bit of a headache...
> Am on debian unstable but no 2.7 in the repos so I'll have to compile
> it...
> Ok can do that but first I'd like to check that this trace 'bug' has
> been cleared
> Where do I look?

Ok Ive got 2.7 from 'experimental' without any (apparent) glitches
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trace cmd line args

2010-12-09 Thread rusi
On Dec 9, 9:03 pm, Terry Reedy  wrote:
> On 12/9/2010 7:12 AM, rusi wrote:
>
> > On Dec 9, 1:39 pm, Terry Reedy  wrote:
> >> On 12/9/2010 1:10 AM, rusi wrote:
>
> >>> I am unable to get trace to not trace system modules.
>
> >> Try it with 3.2b1, just released. Multiple bugs were fixed in trace.
> >> Some fixes might also be in recent 2.7.1 and 3.1.3. Not sure.
>
> >> --
> >> Terry Jan Reedy
>
> > I am doing this to port a 2.x app to 3 which is giving me a hell of a
> > time! :-;
>
> I would get it to run on 2.7 first, with out getting any
> DeprecationWarnings when they are turned on. They are off by default and
> I am not sure how to turn on but presume the warnings module doc says how.
>
> --
> Terry Jan Reedy

This is a bit of a headache...
Am on debian unstable but no 2.7 in the repos so I'll have to compile
it...
Ok can do that but first I'd like to check that this trace 'bug' has
been cleared
Where do I look?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comparisons of incompatible types

2010-12-09 Thread John Nagle

On 12/9/2010 12:36 AM, Terry Reedy wrote:

On 12/9/2010 2:58 AM, Steven D'Aprano wrote:

On Wed, 08 Dec 2010 20:16:57 -0800, John Nagle wrote:

I believe that is that exactly one of <,=.> are true.


Not for NaNs.

>>> NaN = float('nan')
>>> NaN == NaN
False
>>> NaN > NaN
False
>>> NaN < NaN
False

   That's IEEE 754 compliant.  NaN is not equal to NaN.
That's by design.  But it really messes up sorting.

   Python "dict" types, however, treat "NaN" as a unique value,
because they're hash based on the underlying representation.

   (The best coverage of this whole topic was the Apple Numerics Manual
for the original Mac.  Apple hired the floating point expert from
Berkeley to get this right. Then Apple went from the M68xxx series
to the IBM PowerPC, and 80-bit floats to 64-bit floats, breaking all
the engineering applications, most of which were never ported to the
PowerPC.)

John Nagle


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


Re: 64 bit memory usage

2010-12-09 Thread Benjamin Kaplan
On Thursday, December 9, 2010, Rob Randall  wrote:
> But the C++ program using up memory does not slow up.
> It has gone to 40GB without much trouble.
>

Your C++ program probably doesn't have a garbage collector traversing
the entire allocated memory looking for reference cycles.

> Does anyone have a 64 bit python application that uses more the 2GB?
>
> On 9 December 2010 16:54, Antoine Pitrou  wrote:
> On Wed, 8 Dec 2010 14:44:30 +
> Rob Randall  wrote:
>> I am trying to understand how much memory is available to a 64 bit python
>> process running under Windows XP 64 bit.
>>
>> When I run tests just creating a series of large dictionaries containing
>> string keys and float values I do not seem to be able to grow the process
>> beyond the amount of RAM present.
>>
>> For example, on a box with 2GB RAM and 3 GB pagefile the process stalls at
>> around 2GB.
>>
>> On another machine with 16GB RAM and 24GB pagefile the process stalls at
>> 16GB.
>
> How is it surprising? When you go past the available RAM, your process
> starts swapping and everything becomes incredibly slower.
>
> Regards
>
> Antoine.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 64 bit memory usage

2010-12-09 Thread John Nagle

On 12/8/2010 11:40 PM, Ian Kelly wrote:

Since a process need not have all its pages in physical memory
simultaneously, there is no reason to suppose that a single process
could not consume the entirety of the available virtual memory (minus
what is used by the operating system) on a 64-bit system (the same
cannot be said of a 32-bit system, where the total virtual memory
available may well be larger than the addressable space).


Actually, the "32-bit" x86 machines since the Pentium Pro
are really 36 to 48-bit machines.  They only offer 32-bit flat address
spaces to user programs, but the MMU and memory interface support a
larger address space.  The page table design supports 64-bit
physical memory, but most of the bits beyond 36 usually aren't
implemented.   Linux fully supported this; Windows tried, but
older drivers were a problem.  That's why there are 32 bit
machines with more than 4GB of RAM.

None of the real 64-bit architectures, from AMD64 to SPARC
to Itanium, need this hack.

John Nagle

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


Re: 64 bit memory usage

2010-12-09 Thread Rob Randall
Basically the process runs at around 1% and it never seems to grow in size
again.
When running the C++ with python app the process slows when a new 'page' is
required but then goes back to 'full' speed. It does this until basically
all the virtual memory is used.

I have had memory exceptions when running the same sort of stuff on 32 bit,
but never 64 bit.

On 9 December 2010 16:54, Antoine Pitrou  wrote:

> On Wed, 8 Dec 2010 14:44:30 +
> Rob Randall  wrote:
> > I am trying to understand how much memory is available to a 64 bit python
> > process running under Windows XP 64 bit.
> >
> > When I run tests just creating a series of large dictionaries containing
> > string keys and float values I do not seem to be able to grow the process
> > beyond the amount of RAM present.
> >
> > For example, on a box with 2GB RAM and 3 GB pagefile the process stalls
> at
> > around 2GB.
> >
> > On another machine with 16GB RAM and 24GB pagefile the process stalls at
> > 16GB.
>
> How is it surprising? When you go past the available RAM, your process
> starts swapping and everything becomes incredibly slower.
>
> Regards
>
> Antoine.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 64 bit memory usage

2010-12-09 Thread Rob Randall
But the C++ program using up memory does not slow up.
It has gone to 40GB without much trouble.

Does anyone have a 64 bit python application that uses more the 2GB?

On 9 December 2010 16:54, Antoine Pitrou  wrote:

> On Wed, 8 Dec 2010 14:44:30 +
> Rob Randall  wrote:
> > I am trying to understand how much memory is available to a 64 bit python
> > process running under Windows XP 64 bit.
> >
> > When I run tests just creating a series of large dictionaries containing
> > string keys and float values I do not seem to be able to grow the process
> > beyond the amount of RAM present.
> >
> > For example, on a box with 2GB RAM and 3 GB pagefile the process stalls
> at
> > around 2GB.
> >
> > On another machine with 16GB RAM and 24GB pagefile the process stalls at
> > 16GB.
>
> How is it surprising? When you go past the available RAM, your process
> starts swapping and everything becomes incredibly slower.
>
> Regards
>
> Antoine.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: run a function in another processor in python

2010-12-09 Thread geremy condra
On Thu, Dec 9, 2010 at 5:03 AM, Astan Chee  wrote:
> Thanks but I'm having trouble with that module too. Currently what I
> have is something like this:
>
> import sys
> import os
> import multiprocessing
>
> import time
>
> def functionTester(num):
>    return ((num+2)/(num-2))**2
>
> num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63]
>
> max_result = 0
>
> start = time.time()
>
> num_processes = multiprocessing.cpu_count()
>
> threads = []
> len_stas = len(num_args)
>
> for list_item in num_args:
>    if len(threads) < num_processes:
>        p = multiprocessing.Process(target=functionTester,args=[list_item])
>        p.start()
>        print p, p.is_alive()
>        threads.append(p)
>    else:
>        for thread in threads:
>            if not thread.is_alive():
>                threads.remove(thread)
>
> print "Result " + str(max_result)
> end = time.time()
> elapsed= end - start
> print "Took", elapsed, "seconds to execute"
>
> But it doesn't give me any return data. It also spawns an infinite
> number of (sub)processes that crashes my machine. What am I doing
> wrong here?
>
> On 12/9/10, Jean-Michel Pichavant  wrote:
>> Astan Chee wrote:
>>> Hi,
>>> I've got a python script that calls a function many times with various
>>> arguments and returns a result. What I'm trying to do is run this
>>> function each on different processors and compile the result at the
>>> end based on the function result. The script looks something like
>>> this:
>>>
>>>
>>> import time
>>>
>>> def functionTester(num):
>>>     return ((num+2)/(num-2))**2
>>>
>>> num_args = [1,2,3,7,12,16,19,35,36,37,38,55,56,57,63,44,71,81,91]
>>>
>>> max_result = 0
>>>
>>> start = time.time()
>>>
>>> for n in num_args:
>>>     result = functionTester(n)
>>>     if result > max_result:
>>>         max_result = result
>>>
>>> print "Result " + str(max_result)
>>> end = time.time()
>>> elapsed= end - start
>>> print "Took", elapsed, "seconds to execute"
>>>
>>>
>>> What I'm trying to do is run each function on a processor and when its
>>> done, move on to the next function-argument specifically on windows 7
>>> x64 using python 2.6. How do I do this?
>>> Thanks for any help
>>>
>> If I'm not wrong, CPU management is handled by your system, meaning
>> there's no way to 'force' anything to run on a specific CPU. However,
>> you may try to execute your fonction in a subprocess, so that the system
>> will use different CPUs (hopefully). You then just need to limit the
>> number of subprocess alive at the same time.
>>
>> Have a look here
>> http://docs.python.org/library/multiprocessing.html
>>
>> JM
>>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Here's a way of doing what I think you mean to do. I assume that
max_result should be the maximum value returned by a run of
functionTester.

Also, just a note, usually function names like this are spelled
function_tester rather than functionTester in python.

If you need to de-python3ify it just change the line at the top and
cast your nums to floats, otherwise you'll get integer division (which
I again assume you don't want).

#! /usr/bin/env python3

import time
import multiprocessing


def functionTester(num):
   return ((num+2)/(num-2))**2

num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63]

num_processes = multiprocessing.cpu_count()
pool = multiprocessing.Pool(num_processes)

start = time.time()
results = pool.map(functionTester, num_args)
end = time.time()

# is this what you meant to do with the results?
max_result = max(results)
print("Result " + str(max_result))

elapsed = end - start
print("Took", elapsed, "seconds to execute")

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


Re: Using a window style in a Toplevel window

2010-12-09 Thread Eric Brunel
In article ,
 pyt...@bdurham.com wrote:

> Eric,
> 
> Besides style support, what are the advantages of ttk.Frame vs.
> Tkinter.Frame?

I'd say none. They are both just containers for other widgets, support 
the same layout managers, and so on. For me, using a ttk.Frame is really 
just for getting the correct theme, nothing else...

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


Re: 64 bit memory usage

2010-12-09 Thread Antoine Pitrou
On Wed, 8 Dec 2010 14:44:30 +
Rob Randall  wrote:
> I am trying to understand how much memory is available to a 64 bit python
> process running under Windows XP 64 bit.
> 
> When I run tests just creating a series of large dictionaries containing
> string keys and float values I do not seem to be able to grow the process
> beyond the amount of RAM present.
> 
> For example, on a box with 2GB RAM and 3 GB pagefile the process stalls at
> around 2GB.
> 
> On another machine with 16GB RAM and 24GB pagefile the process stalls at
> 16GB.

How is it surprising? When you go past the available RAM, your process
starts swapping and everything becomes incredibly slower.

Regards

Antoine.


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


Re: 64 bit memory usage

2010-12-09 Thread Nobody
Rob Randall  wrote:

> I am trying to understand how much memory is available to a 64 bit python
> process running under Windows XP 64 bit.
> 
> When I run tests just creating a series of large dictionaries containing
> string keys and float values I do not seem to be able to grow the process
> beyond the amount of RAM present.
> 
> For example, on a box with 2GB RAM and 3 GB pagefile the process stalls at
> around 2GB.

What do you mean by "stalls"? Do you get an exception, or does the program
just slow to a crawl?

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


Re: trace cmd line args

2010-12-09 Thread Terry Reedy

On 12/9/2010 7:12 AM, rusi wrote:

On Dec 9, 1:39 pm, Terry Reedy  wrote:

On 12/9/2010 1:10 AM, rusi wrote:


I am unable to get trace to not trace system modules.


Try it with 3.2b1, just released. Multiple bugs were fixed in trace.
Some fixes might also be in recent 2.7.1 and 3.1.3. Not sure.

--
Terry Jan Reedy


I am doing this to port a 2.x app to 3 which is giving me a hell of a
time! :-;


I would get it to run on 2.7 first, with out getting any 
DeprecationWarnings when they are turned on. They are off by default and 
I am not sure how to turn on but presume the warnings module doc says how.


--
Terry Jan Reedy

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


Re: Can't deepcopy bytes-derived class

2010-12-09 Thread Terry Reedy

On 12/9/2010 9:19 AM, Dan wrote:


I tested the 4 line change anyway...removing it from 3.2 had no
detrimental effect, adding it to 3.1 had no effect.  It must be
something else.


Then there must have been a change in the bytes object, which is deeper 
than I want to go. 3.2 has a LOT of little improvements. When it comes 
out, just about all 3.1 users should upgrade unless one has production 
code disabled by a bugfix.


--
Terry Jan Reedy

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


Re: completely implicit interpolation based on a frame object

2010-12-09 Thread nn
On Dec 9, 2:29 am, Edward Peschko  wrote:
> >> Any ideas would be great on this, including pitfalls that people see
> >> in implementing it.
>
> >http://docs.python.org/library/string.html#template-strings
>
> > regards
> >  Steve
>
> Steve,
>
> Thanks for the tip, I did look at templates and decided that they
> weren't quite completely what I was looking for, although they could
> be part of the solution.
>
> 1. they require ${ } around the variables in question that you want to
> interpolate. When run through the trace hook, normal code doesn't do
> that.
> 2. they don't provide (AFAICT) a complete interpolation solution.
> Suppose I want to define custom interpolations in my tracer, like say,
> expanding out lists and dicts, or fleshing out objects using their
> stringification method. Does template do this?
>
> Formats may be a bit closer here, but I'm not sure if they are
> workable (or usable) with 2.5... which is where I need to work.
>
> Ed

One of the solutions from here might work for you:

http://wiki.python.org/moin/Templating
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: run a function in another processor in python

2010-12-09 Thread Peter Otten
Astan Chee wrote:

> Thanks but I'm having trouble with that module too. Currently what I
> have is something like this:
> 
> import sys
> import os
> import multiprocessing
> 
> import time
> 
> def functionTester(num):
> return ((num+2)/(num-2))**2
> 
> num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63]
> 
> max_result = 0
> 
> start = time.time()
> 
> num_processes = multiprocessing.cpu_count()
> 
> threads = []
> len_stas = len(num_args)
> 
> for list_item in num_args:
> if len(threads) < num_processes:
> p =
> multiprocessing.Process(target=functionTester,args=[list_item])
> p.start() print p, p.is_alive()
> threads.append(p)
> else:
> for thread in threads:
> if not thread.is_alive():
> threads.remove(thread)
> 
> print "Result " + str(max_result)
> end = time.time()
> elapsed= end - start
> print "Took", elapsed, "seconds to execute"
> 
> But it doesn't give me any return data. It also spawns an infinite
> number of (sub)processes that crashes my machine. What am I doing
> wrong here?

I can't replicate the crash. However, your problem looks like there is a 
ready-to-use solution:

http://docs.python.org/library/multiprocessing.html#using-a-pool-of-workers

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


Re: Can't deepcopy bytes-derived class

2010-12-09 Thread Dan
On Dec 8, 9:05 pm, Terry Reedy  wrote:
> On 12/8/2010 7:11 PM, Ned Deily wrote:
>
>
>
>
>
>
>
>
>
> > In article, Terry
> > Reedy  wrote:
> >> On 12/8/2010 2:42 PM, Dan wrote:
> >>> I have a simple type derived from bytes...
>
> >>> class atom(bytes): pass
>
> >>> ... that I cannot deepcopy().  The session below demonstrates
> >>> how deepcopy() of "bytes" works fine, but deepcopy() of "atom"
> >>> does not.
> > [...]
> >>> Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32
> >>> bit (Intel)] Type "help", "copyright", "credits" or "license" for
> >>> more information.
> >> import copy class atom(bytes):
> >>> ...        pass ...
> >> copy.deepcopy(b'abc')
> >>> b'abc'
> >> copy.deepcopy(atom(b'abc'))
> >>> Traceback (most recent call last): File "C:\Program Files
> >>> (x86)\Wing IDE 3.2\src\debug\tserver \_sandbox.py", line 1,
> >>> in # Used internally for debug sandbox under external
> >>> interpreter File "C:\Python31\Lib\copy.py", line 173, in
> >>> deepcopy y = _reconstruct(x, rv, 1, memo) File
> >>> "C:\Python31\Lib\copy.py", line 280, in _reconstruct y =
> >>> callable(*args) File "C:\Python31\Lib\copyreg.py", line 88, in
> >>> __newobj__ return cls.__new__(cls, *args) builtins.TypeError:
> >>> string argument without an encoding
>
> >> You could trace through copy.py and copyreg.py to see where bytes
> >> and atom get treated differently.
>
> >> This might be a bug that should be reported on the tracker, but I
> >> do not know. Let see what anyone else says.
>
> > FWIW, the example still fails with Python 3.1.3 but seems to work OK
> > with a recent alpha build of Python 3.2.  What specific change might
> > have fixed it doesn't come immediately to mind.
>
> According to difflib.unified_diff, the only difference between
> Lib/copy.py from 3.1 to 3.2 is 4 lines:
> +
> +def _deepcopy_method(x, memo): # Copy instance methods
> +    return type(x)(x.__func__, deepcopy(x.__self__, memo))
> +_deepcopy_dispatch[types.MethodType] = _deepcopy_method
>
> (and none in copyreg.py)
>
> These were added in rev76572 as part ofhttp://bugs.python.org/issue1515
>
> Guido decreed this to be a new feature rather than bugfix, so the change
> went into future 2.7 and 3.2 and not existing 2.6 and 3.1.
>
> Tto verify that these cause the change, comment out in 3.2 or add to
> 3.1. I have not read through the issue to understand it or why it would
> affect the OP's code case.
>
> --
> Terry Jan Reedy

Thank you everyone.  Knowing that it works in 3.2 is good enough for
me.

I tested the 4 line change anyway...removing it from 3.2 had no
detrimental effect, adding it to 3.1 had no effect.  It must be
something else.

Regards,
Dan.





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


Re: kinterbasdb error connection

2010-12-09 Thread Uwe Grauer
On 12/07/2010 04:35 PM, Ale Ghelfi wrote:
> (i'm under Ubuntu 10.10 amd64 and python 2.6 and kinterbasdb 3.2 )
> I try to connect my database of firebird 2.5 by kinterbasdb.
> But python return this error :


You are not using the current kinterbasdb version.
See:
http://firebirdsql.org/index.php?op=devel&sub=python

Uwe

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


Re: Replacing globals in exec by custom class

2010-12-09 Thread Jonathan S
Thanks for your response! (And sorry about the syntax error, I forgot
to test my code after cleaning up some debug statements before
posting, the else should have been elif indeed.)

It's very interesing, how Python works internally. According to a
thread on the Python mailing list in 2002, it seems that the
implementation of CPython bypasses __getitem__ of the dict object,
when it is used as Global namespace. (For performance reasons.)

http://mail.python.org/pipermail/python-dev/2002-October/029753.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: 64 bit memory usage

2010-12-09 Thread Heather Brown

On 01/-10/-28163 02:59 PM, Dennis Lee Bieber wrote:

On Wed, 8 Dec 2010 14:44:30 +, Rob Randall
declaimed the following in gmane.comp.python.general:


I am trying to understand how much memory is available to a 64 bit python
process running under Windows XP 64 bit.

When I run tests just creating a series of large dictionaries containing
string keys and float values I do not seem to be able to grow the process
beyond the amount of RAM present.

For example, on a box with 2GB RAM and 3 GB pagefile the process stalls at
around 2GB.

On another machine with 16GB RAM and 24GB pagefile the process stalls at
16GB.



Probably need to ask M$, but I can understand this behavior as a
hypothetical...

The page file can be larger than physical memory because it contains
memory "images" for multiple processes. However, all those "images" have
to map into the physically addressable memory -- so a process is likely
limited to physical memory, but you can have multiple processes adding
up to physical + pagefile in total.


It's plausible that MS did that, but it's not reasonable.  An 
application's entire data space is never in physical memory, except for 
trivial applications.  When new pages are needed, old ones are swapped 
out, in an LRU manner.  If the application is the only thing "running," 
it'll eventually be mapped into most of physical memory, but even then, 
the swapper keeps some back.


The limit in 32bit world was 4gb, not whatever RAM happened to be in the 
machine.  That limit came from the address space (or linear space, as MS 
calls it), not from the amount of RAM.  It's only in recent years that 
those numbers have tended to be close.


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


Re: packaging python code in zip file

2010-12-09 Thread Peter Otten
mark jason wrote:

> hi,
> I have created a python app in eclipse pydev .The app is structured as
> below..
> 
> mypackage
>   |__ __init__.py
>   |__ driver.py
>   |__ helper.py
>   |__ utils.py
> 
> The driver.py has the main program.I have added if
> __name__=="__main__" block in  the
> 
> driver.py and pydev's run configuration has the following values,
> Project : myproject
> Main Module :${workspace_loc:myproject/src/mypackage/driver.py}
>  So,the app runs in pydev without any problems.
> 
> Then I thought of providing the modules as a zip file.So I created a
> zip file containing
> mypackage directory.The user should be able to unzip the zip file and
> run the application from command line .
> 
> What bothers me is that ,the user will have to cd to mypackage folder
> and run python driver.py..
> This doesn't look like the proper way..
> I also thought of  putting the driver,helper,utils modules in a folder
> called mycode and zipping it without the __init__.py file .
> I am not sure which is the correct way.
> Can somebody advise me as to how I can package it better?

If you put a __main__.py file at the top level you can run the zip archive 
directly (requires Python 2.6):

$ echo 'import alpha
> print "main"' > __main__.py
$ mkdir alpha
$ echo 'print "init alpha"' > alpha/__init__.py
$ zip -r demo .
  adding: alpha/ (stored 0%)
  adding: alpha/__init__.py (stored 0%)
  adding: __main__.py (stored 0%)
$ rm -rf __main__.py alpha/
$ ls
demo.zip
$ python demo.zip
init alpha
main

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


Re: run a function in another processor in python

2010-12-09 Thread Astan Chee
Thanks but I'm having trouble with that module too. Currently what I
have is something like this:

import sys
import os
import multiprocessing

import time

def functionTester(num):
return ((num+2)/(num-2))**2

num_args = [61,62,33,7,12,16,19,35,36,37,38,55,56,57,63]

max_result = 0

start = time.time()

num_processes = multiprocessing.cpu_count()

threads = []
len_stas = len(num_args)

for list_item in num_args:
if len(threads) < num_processes:
p = multiprocessing.Process(target=functionTester,args=[list_item])
p.start()
print p, p.is_alive()
threads.append(p)
else:
for thread in threads:
if not thread.is_alive():
threads.remove(thread)

print "Result " + str(max_result)
end = time.time()
elapsed= end - start
print "Took", elapsed, "seconds to execute"

But it doesn't give me any return data. It also spawns an infinite
number of (sub)processes that crashes my machine. What am I doing
wrong here?

On 12/9/10, Jean-Michel Pichavant  wrote:
> Astan Chee wrote:
>> Hi,
>> I've got a python script that calls a function many times with various
>> arguments and returns a result. What I'm trying to do is run this
>> function each on different processors and compile the result at the
>> end based on the function result. The script looks something like
>> this:
>>
>>
>> import time
>>
>> def functionTester(num):
>> return ((num+2)/(num-2))**2
>>
>> num_args = [1,2,3,7,12,16,19,35,36,37,38,55,56,57,63,44,71,81,91]
>>
>> max_result = 0
>>
>> start = time.time()
>>
>> for n in num_args:
>> result = functionTester(n)
>> if result > max_result:
>> max_result = result
>>
>> print "Result " + str(max_result)
>> end = time.time()
>> elapsed= end - start
>> print "Took", elapsed, "seconds to execute"
>>
>>
>> What I'm trying to do is run each function on a processor and when its
>> done, move on to the next function-argument specifically on windows 7
>> x64 using python 2.6. How do I do this?
>> Thanks for any help
>>
> If I'm not wrong, CPU management is handled by your system, meaning
> there's no way to 'force' anything to run on a specific CPU. However,
> you may try to execute your fonction in a subprocess, so that the system
> will use different CPUs (hopefully). You then just need to limit the
> number of subprocess alive at the same time.
>
> Have a look here
> http://docs.python.org/library/multiprocessing.html
>
> JM
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Comparisons of incompatible types

2010-12-09 Thread Mark Wooding
John Nagle  writes:

> >>> NaN = float("nan")
> >>> arr = [1.0, 4.0, 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0, 1.0, 4.0, 
> 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0]
> >>> sorted(arr)
> [0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 5.0, nan, 5.0, 6.0,
> nan, 4.0, nan, 6.0, nan]
>
> The sorted numerical values aren't in order. 

Indeed.  You failed to provide a valid ordering to `sorted'.  By failing
to satisfy its precondition, you relieved it of its obligation to
satisfy its postcondition.

> "sort" has failed because it assumes that a < b and b < c implies a <
> c. But that's not a valid assumption here.
>
> It's not good to break trichotomy.

You're confused.  The property

a < b and b < c => a < c

is called `transitivity'.  But the `float' ordering /is/ transitive.
Note that a < b implies that neither a nor b is a NaN.

Also, trichotomy is unnecessary for sorting, and Python's `sort' method
doesn't require it; it does require a total preorder, though.  What
properties does a total preorder require?

  1. Transitivity: a <= b and b <= c => a <= c

  2. Totality: a <= b or b <= a

The above list sorting goes wrong because the `float' ordering isn't
total.  In particular, x http://mail.python.org/mailman/listinfo/python-list


Re: A web site using Python

2010-12-09 Thread Stefaan Himpe

1. Pick a web framework, I'd suggest looking at:


web2py: http://web2py.com - probably the easiest to install (no 
configuration needed) and learn. Suitable for both small and big 
projects. No worries when upgrading to a newer version as backward 
compatibility is an explicit design goal.


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


Re: Using a window style in a Toplevel window

2010-12-09 Thread python
Eric,

Besides style support, what are the advantages of ttk.Frame vs.
Tkinter.Frame?

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


Re: trace cmd line args

2010-12-09 Thread rusi
On Dec 9, 1:39 pm, Terry Reedy  wrote:
> On 12/9/2010 1:10 AM, rusi wrote:
>
> > I am unable to get trace to not trace system modules.
>
> Try it with 3.2b1, just released. Multiple bugs were fixed in trace.
> Some fixes might also be in recent 2.7.1 and 3.1.3. Not sure.
>
> --
> Terry Jan Reedy

I am doing this to port a 2.x app to 3 which is giving me a hell of a
time! :-;
-- 
http://mail.python.org/mailman/listinfo/python-list


[Fwd: Re: Using a window style in a Toplevel window]

2010-12-09 Thread craf
- Mensaje reenviado 
> De: Eric Brunel 
> Para: python-list@python.org
> Asunto: Re: Using a window style in a Toplevel window
> Fecha: Thu, 09 Dec 2010 10:00:39 +0100
> Grupos de noticias: comp.lang.python
> 
> In article ,
>  craf  wrote:
> 
> > Hi.
> > 
> > I use Python 3.1 and Tkinter.ttk 8.5 on Ubuntu 9.10.
> > 
> > CODE:
> > 
> > module:FMain.py
> > 
> > from tkinter import ttk
> > from FSecondWindow import *
> > 
> > class App:
> > def __init__(self,master):
> > 
> > button1 = ttk.Button(master,text='Show
> > TopLevel',command=lambda:window())
> > button1.pack()
> > 
> >
> > master = Tk()
> > app = App(master)
> > style = ttk.Style()
> > style.theme_use('clam')
> > master.mainloop()
> > 
> > 
> > module:FSecondWindow.py
> > 
> > from tkinter import *
> > from tkinter import ttk
> > 
> > def window():
> > t = Toplevel()
> > button2 = Button(t,text='Hello').pack()
> > 
> > 
> > CODE EXPLANATION:---
> > 
> > 1. From the main module FMain.py call the window function that is
> > located in FSecondWindow module and create a toplevel window.
> > 
> > 2.I apply a theme called 'clam' to the master window to improve the
> > appearance of their widgets.
> > 
> > QUERY:--
> > 
> > How I can make the toplevel window also take the theme 'clam'?
> 
> Short answer: you can't. No directly anyway.
> 
> Long answer: As you might be aware, there are 2 widget sets in 
> tk/tkinter, the "old" one for which classes are directly in the tkinter 
> module, and the new one that are in the ttk submodule. Only the second 
> set supports theming, not the first one. Unfortunately, there are a few 
> widgets that exist only in the first set, and Toplevel is one of those. 
> So no theming is directly available for toplevels, and you can change 
> whatever you want via style.theme_use, it won't be reflected on 
> toplevels.
> 
> By the way, as you wrote the code above, it won't be reflected on your 
> button either, since you used the Button class, which is taken in 
> tkinter directly, so it is the "old" Button class, not the new one. To 
> get the new one, use ttk.Button, not Button.
> 
> For your toplevel, there is however a simple workaround: Since there is 
> a Frame widget in the new widget set, you can simply insert such a frame 
> in your toplevel, make sure it will take the whole space, and then 
> insert your widgets in this frame rather than in the toplevel directly. 
> The code for your 'window' function would then become:
> 
> def window()
> t = Toplevel()
> frm = ttk.Frame(t)
> frm.pack(fill=BOTH, expand=True)
> button2 = ttk.Button(frm, text='Hello')
> button2.pack()
> 
> (Note also that I have put the creation of the button and its packing in 
> 2 lines. You should never do variable = widget.pack(…) since pack does 
> not return the widget. It always returns None, so doing so won't put 
> your widget in the variable).
> 
> The code above should do what you're after.
> 
> > Thanks in advance.
> 
> HTH
>  - Eric -


Hi Eric.

¡Thank you very much, for the answer.!

Regards

Cristian Abarzúa F

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


Re: packaging python code in zip file

2010-12-09 Thread Nitin Pawar
have u tried using setuptools and distutils

they are used for python package distributions

On Thu, Dec 9, 2010 at 5:02 PM, mark jason  wrote:

> hi,
> I have created a python app in eclipse pydev .The app is structured as
> below..
>
> mypackage
>  |__ __init__.py
>  |__ driver.py
>  |__ helper.py
>  |__ utils.py
>
> The driver.py has the main program.I have added if
> __name__=="__main__" block in  the
>
> driver.py and pydev's run configuration has the following values,
> Project : myproject
> Main Module :${workspace_loc:myproject/src/mypackage/driver.py}
>  So,the app runs in pydev without any problems.
>
> Then I thought of providing the modules as a zip file.So I created a
> zip file containing
> mypackage directory.The user should be able to unzip the zip file and
> run the application from command line .
>
> What bothers me is that ,the user will have to cd to mypackage folder
> and run python driver.py..
> This doesn't look like the proper way..
> I also thought of  putting the driver,helper,utils modules in a folder
> called mycode and zipping it without the __init__.py file .
> I am not sure which is the correct way.
> Can somebody advise me as to how I can package it better?
>
> thanks,
>
> mark
> --
> http://mail.python.org/mailman/listinfo/python-list
>



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


packaging python code in zip file

2010-12-09 Thread mark jason
hi,
I have created a python app in eclipse pydev .The app is structured as
below..

mypackage
  |__ __init__.py
  |__ driver.py
  |__ helper.py
  |__ utils.py

The driver.py has the main program.I have added if
__name__=="__main__" block in  the

driver.py and pydev's run configuration has the following values,
Project : myproject
Main Module :${workspace_loc:myproject/src/mypackage/driver.py}
 So,the app runs in pydev without any problems.

Then I thought of providing the modules as a zip file.So I created a
zip file containing
mypackage directory.The user should be able to unzip the zip file and
run the application from command line .

What bothers me is that ,the user will have to cd to mypackage folder
and run python driver.py..
This doesn't look like the proper way..
I also thought of  putting the driver,helper,utils modules in a folder
called mycode and zipping it without the __init__.py file .
I am not sure which is the correct way.
Can somebody advise me as to how I can package it better?

thanks,

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


Re: run a function in another processor in python

2010-12-09 Thread Jean-Michel Pichavant

Astan Chee wrote:

Hi,
I've got a python script that calls a function many times with various
arguments and returns a result. What I'm trying to do is run this
function each on different processors and compile the result at the
end based on the function result. The script looks something like
this:


import time

def functionTester(num):
return ((num+2)/(num-2))**2

num_args = [1,2,3,7,12,16,19,35,36,37,38,55,56,57,63,44,71,81,91]

max_result = 0

start = time.time()

for n in num_args:
result = functionTester(n)
if result > max_result:
max_result = result

print "Result " + str(max_result)
end = time.time()
elapsed= end - start
print "Took", elapsed, "seconds to execute"


What I'm trying to do is run each function on a processor and when its
done, move on to the next function-argument specifically on windows 7
x64 using python 2.6. How do I do this?
Thanks for any help
  
If I'm not wrong, CPU management is handled by your system, meaning 
there's no way to 'force' anything to run on a specific CPU. However, 
you may try to execute your fonction in a subprocess, so that the system 
will use different CPUs (hopefully). You then just need to limit the 
number of subprocess alive at the same time.


Have a look here
http://docs.python.org/library/multiprocessing.html

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


run a function in another processor in python

2010-12-09 Thread Astan Chee
Hi,
I've got a python script that calls a function many times with various
arguments and returns a result. What I'm trying to do is run this
function each on different processors and compile the result at the
end based on the function result. The script looks something like
this:


import time

def functionTester(num):
return ((num+2)/(num-2))**2

num_args = [1,2,3,7,12,16,19,35,36,37,38,55,56,57,63,44,71,81,91]

max_result = 0

start = time.time()

for n in num_args:
result = functionTester(n)
if result > max_result:
max_result = result

print "Result " + str(max_result)
end = time.time()
elapsed= end - start
print "Took", elapsed, "seconds to execute"


What I'm trying to do is run each function on a processor and when its
done, move on to the next function-argument specifically on windows 7
x64 using python 2.6. How do I do this?
Thanks for any help
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using a window style in a Toplevel window

2010-12-09 Thread Eric Brunel
In article ,
 craf  wrote:

> Hi.
> 
> I use Python 3.1 and Tkinter.ttk 8.5 on Ubuntu 9.10.
> 
> CODE:
> 
> module:FMain.py
> 
> from tkinter import ttk
> from FSecondWindow import *
> 
> class App:
> def __init__(self,master):
> 
> button1 = ttk.Button(master,text='Show
> TopLevel',command=lambda:window())
> button1.pack()
> 
>
> master = Tk()
> app = App(master)
> style = ttk.Style()
> style.theme_use('clam')
> master.mainloop()
> 
> 
> module:FSecondWindow.py
> 
> from tkinter import *
> from tkinter import ttk
> 
> def window():
> t = Toplevel()
> button2 = Button(t,text='Hello').pack()
> 
> 
> CODE EXPLANATION:---
> 
> 1. From the main module FMain.py call the window function that is
> located in FSecondWindow module and create a toplevel window.
> 
> 2.I apply a theme called 'clam' to the master window to improve the
> appearance of their widgets.
> 
> QUERY:--
> 
> How I can make the toplevel window also take the theme 'clam'?

Short answer: you can't. No directly anyway.

Long answer: As you might be aware, there are 2 widget sets in 
tk/tkinter, the "old" one for which classes are directly in the tkinter 
module, and the new one that are in the ttk submodule. Only the second 
set supports theming, not the first one. Unfortunately, there are a few 
widgets that exist only in the first set, and Toplevel is one of those. 
So no theming is directly available for toplevels, and you can change 
whatever you want via style.theme_use, it won't be reflected on 
toplevels.

By the way, as you wrote the code above, it won't be reflected on your 
button either, since you used the Button class, which is taken in 
tkinter directly, so it is the "old" Button class, not the new one. To 
get the new one, use ttk.Button, not Button.

For your toplevel, there is however a simple workaround: Since there is 
a Frame widget in the new widget set, you can simply insert such a frame 
in your toplevel, make sure it will take the whole space, and then 
insert your widgets in this frame rather than in the toplevel directly. 
The code for your 'window' function would then become:

def window()
t = Toplevel()
frm = ttk.Frame(t)
frm.pack(fill=BOTH, expand=True)
button2 = ttk.Button(frm, text='Hello')
button2.pack()

(Note also that I have put the creation of the button and its packing in 
2 lines. You should never do variable = widget.pack(…) since pack does 
not return the widget. It always returns None, so doing so won't put 
your widget in the variable).

The code above should do what you're after.

> Thanks in advance.

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


Re: is py2exe still active ?

2010-12-09 Thread Octavian Rasnita
Hi Philip,

I thought that pypi works like cpan for Perl, but now I understand.

Thank you for clarifications.


--
Octavian


---
From: "Philip Semanchuk" 
> 
> On Dec 8, 2010, at 5:09 AM, Octavian Rasnita wrote:
> 
>> Hi Steve,
>> 
>> I may put some stupid questions because I am very new to Python, but... I 
>> heard about pypi/pip. Aren't all these Python libraries (like cxFreeze) 
>> provided on a central archive where we can get them and also report the bugs 
>> using a single request/issue tracker?
> 
> Hi Octavian,
> I didn't see anyone reply to you on the list...
> 
> The short answer to your question is "no". PyPI stands for the Python Package 
> Index. The key word there is "Index". It's a catalog of packages but many of 
> those packages are hosted elsewhere. The places where those packages are 
> hosted may or may not have an issue tracker, etc. 
> 
> For instance, one the packages that I offer through PyPI (posix_ipc) is 
> hosted on my personal Web site. 
> 
> Hope this helps
> Philip
> 
> 
>> - Original Message - 
>> From: "Steve Holden" 
>> Newsgroups: gmane.comp.python.general
>> To: "Octavian Rasnita" 
>> Cc: 
>> Sent: Wednesday, December 08, 2010 12:56 AM
>> Subject: Re: is py2exe still active ?
>> 
>> 
>>> Octavian:
>>> 
>>> It's great that you want to let people know about bugs. Put yourself in
>>> the position of the package maintainer, however. She or he doesn't spend
>>> all day working on cxFreeze, and probably doesn't even do a Google
>>> search on cxFreeze very often. So they are unlikely to find out about
>>> this problem form your well-intentioned note.
>>> 
>>> It's just possible nobody does care, as I can't find a link to an issue
>>> tracker - the best I could advise in this case would be to join the
>>> mailing list by visiting
>>> 
>>> https://lists.sourceforge.net/lists/listinfo/cx-freeze-users
>>> 
>>> regards
>>> Steve
>>> 
>>> On 12/7/2010 6:49 PM, Octavian Rasnita wrote:
 This packager is also nice.
 
 If someone cares, I've discovered a small bug in it.
 If Python is installed on another drive than C under Windows, the 
 cxfreeze.bat file still calls Python on the drive C and it doesn't work 
 until it is corrected.
 
 Octavian
 
 - Original Message - 
 From: "Cbast" 
 Newsgroups: comp.lang.python
 To: 
 Sent: Tuesday, December 07, 2010 5:00 PM
 Subject: Re: is py2exe still active ?
 
 
 On Dec 7, 8:23 am, Anders Persson  wrote:
> Hi!
> When a look att py2exe homepage it is not looking like mutch happen,
> as a beginner i was thinking to start with Python 3, but i like to now
> if py2exe will be for 3 too.
> 
> Is any one have any info ?
 
 I don't have the answer about py2exe, but I'm using cxFreeze to create
 executables with Python 3.1, if it's what you're looking for.
 
 http://cx-freeze.sourceforge.net/
>>> 
>>> 
>>> -- 
>>> Steve Holden   +1 571 484 6266   +1 800 494 3119
>>> PyCon 2011 Atlanta March 9-17   http://us.pycon.org/
>>> See Python Video!   http://python.mirocommunity.org/
>>> Holden Web LLC http://www.holdenweb.com/
>> -- 
>> http://mail.python.org/mailman/listinfo/python-list
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trace cmd line args

2010-12-09 Thread Terry Reedy

On 12/9/2010 1:10 AM, rusi wrote:

I am unable to get trace to not trace system modules.


Try it with 3.2b1, just released. Multiple bugs were fixed in trace.
Some fixes might also be in recent 2.7.1 and 3.1.3. Not sure.

--
Terry Jan Reedy

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


Re: Comparisons of incompatible types

2010-12-09 Thread Terry Reedy

On 12/9/2010 2:58 AM, Steven D'Aprano wrote:

On Wed, 08 Dec 2010 20:16:57 -0800, John Nagle wrote:


 Here's an example where this issue produces invalid results in
 Python.

  >>>  NaN = float("nan")
  >>>  arr = [1.0, 4.0, 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0, 1.0, 4.0,
3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0]
  >>>  sorted(arr)
[0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 5.0, nan, 5.0,
6.0, nan, 4.0, nan, 6.0, nan]

The sorted numerical values aren't in order. Note the 4.0 near the end,
after the 6.0.  "sort" has failed because it assumes that a<  b and b<
c implies a<  c. But that's not a valid assumption here.


This is transitivity.


It's not good to break trichotomy.


I believe that is that exactly one of <,=.> are true.



--
Terry Jan Reedy

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


Re: Comparisons of incompatible types

2010-12-09 Thread Steven D'Aprano
On Wed, 08 Dec 2010 20:16:57 -0800, John Nagle wrote:

> Here's an example where this issue produces invalid results in
> Python.
> 
>  >>> NaN = float("nan")
>  >>> arr = [1.0, 4.0, 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0, 1.0, 4.0,
> 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0]
>  >>> sorted(arr)
> [0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 5.0, nan, 5.0,
> 6.0, nan, 4.0, nan, 6.0, nan]
> 
> The sorted numerical values aren't in order. Note the 4.0 near the end,
> after the 6.0.  "sort" has failed because it assumes that a < b and b <
> c implies a < c. But that's not a valid assumption here.
> 
> It's not good to break trichotomy.

It's perfectly fine to break trichotomy. People do it all the time -- 
they prefer chicken to pizza, pizza to steak, but prefer steak to 
chicken. (Modulo whatever foods you prefer. Or sports, or politicians, or 
any one of many things which don't make up an equivalence relationship.) 
Equivalence relationships make up only a tiny portion of relationships, 
and it is both useful and conventional to use the same operators in both 
situations. 

What's not good is to assume trichotomy when it doesn't apply, but that's 
no different from any other faulty assumption, e.g. a coder who assumes 
multiplication is always commutative may be puzzled why his matrix 
calculations are frequently wrong.

Python's sort assumes trichotomy, even when sorting floats. Perhaps it 
shouldn't. But one way or another, that's an issue with sort, not with 
the idea that there are data types where trichotomy doesn't apply. And 
like it or not, floats are one of those data types, just as neither 
commutativity nor associativity applies to floats -- even excluding NANs 
and INFs.



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