Tuesday, February 9, 2010

comp.lang.python - 25 new messages in 13 topics - digest

comp.lang.python
http://groups.google.com/group/comp.lang.python?hl=en

comp.lang.python@googlegroups.com

Today's topics:

* equivalent of Ruby's Pathname? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/f580fb3763208425?hl=en
* ANN: obfuscate - 4 messages, 4 authors
http://groups.google.com/group/comp.lang.python/t/6374e775e474ee1a?hl=en
* Possible? Python 2.6.x and PythonWin on 64-bit Windows 7 - 1 messages, 1
author
http://groups.google.com/group/comp.lang.python/t/967738261a47aeff?hl=en
* EAFP gone wrong - 5 messages, 4 authors
http://groups.google.com/group/comp.lang.python/t/fad74ab9f7cf4047?hl=en
* I've built Python, but can't figure out how to package it for windows - 3
messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/98343a7bbda5e7a1?hl=en
* Programing family - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/9c369186368028ed?hl=en
* Modifying Class Object - 3 messages, 3 authors
http://groups.google.com/group/comp.lang.python/t/fd36962c4970ac48?hl=en
* Easter Eggs - 2 messages, 2 authors
http://groups.google.com/group/comp.lang.python/t/9ce0fe4123739cc4?hl=en
* How to measure elapsed time under Windows? - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/340c476d0357a7bd?hl=en
* New to Python - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/429d23f88afefef6?hl=en
* Ternary plus - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/05afedbd6dc66a2c?hl=en
* Problem Regarding Queue - 1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/74b045cda204e5ee?hl=en
* PyCon is coming! Tomorrow, Feb. 10 is the last day for pre-conference rates -
1 messages, 1 author
http://groups.google.com/group/comp.lang.python/t/23b922c14b1432f0?hl=en

==============================================================================
TOPIC: equivalent of Ruby's Pathname?
http://groups.google.com/group/comp.lang.python/t/f580fb3763208425?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Feb 9 2010 2:28 pm
From: Chris Rebert


On Tue, Feb 9, 2010 at 6:00 AM, Phlip <phlip2005@gmail.com> wrote:
<snip>
> Ah, now we get down to the root of the problem. Because Python is so
> stuck on the "one best way to do it" mentality, language bigotry
> prevented the Committee from picking from among several equally valid
> but non-best options. And after 20 years of growth, Python still has
> no Pathname class. What a mature community! C-:

Committee? I think you have us confused with C++...

*wink*,
Chris

==============================================================================
TOPIC: ANN: obfuscate
http://groups.google.com/group/comp.lang.python/t/6374e775e474ee1a?hl=en
==============================================================================

== 1 of 4 ==
Date: Tues, Feb 9 2010 2:42 pm
From: David Robinow


On Tue, Feb 9, 2010 at 5:10 PM, Simon Brunning <simon@brunningonline.net> wrote:
> On 9 February 2010 16:29, Robert Kern <robert.kern@gmail.com> wrote:
>> On 2010-02-09 09:37 AM, Daniel Fetchinson wrote:
>>> If the code base stabilizes in a production version after losing the
>>> alphas and betas they would be a great addition to the stdlib, I
>>> think.
>>
>> Why?
>
> I agree. Why wait? Put them in the stdlib now!
>
> --
> Cheers,
> Simon B.
Can we please stop this?


== 2 of 4 ==
Date: Tues, Feb 9 2010 3:09 pm
From: "Alf P. Steinbach"


* David Robinow:
> On Tue, Feb 9, 2010 at 5:10 PM, Simon Brunning <simon@brunningonline.net> wrote:
>> On 9 February 2010 16:29, Robert Kern <robert.kern@gmail.com> wrote:
>>> On 2010-02-09 09:37 AM, Daniel Fetchinson wrote:
>>>> If the code base stabilizes in a production version after losing the
>>>> alphas and betas they would be a great addition to the stdlib, I
>>>> think.
>>> Why?
>> I agree. Why wait? Put them in the stdlib now!
>>
> Can we please stop this?

I agree.

I haven't looked at the code but the functionality that's listed is useful, e.g.
in a Usenet client, and it's fun to play around with for a beginner.

Also, for example, Christian Heimes wrote else-thread: «Your work should be
interesting for everybody who has read Simon Sing's "The Code Book: The Science
of Secrecy from Ancient Egypt to Quantum"» (and I for one have that book).


Cheers,

- Alf


== 3 of 4 ==
Date: Tues, Feb 9 2010 3:27 pm
From: Stef Mientki


On 10-02-2010 00:09, Alf P. Steinbach wrote:
> * David Robinow:
>> On Tue, Feb 9, 2010 at 5:10 PM, Simon Brunning
>> <simon@brunningonline.net> wrote:
>>> On 9 February 2010 16:29, Robert Kern <robert.kern@gmail.com> wrote:
>>>> On 2010-02-09 09:37 AM, Daniel Fetchinson wrote:
>>>>> If the code base stabilizes in a production version after losing the
>>>>> alphas and betas they would be a great addition to the stdlib, I
>>>>> think.
>>>> Why?
>>> I agree. Why wait? Put them in the stdlib now!
>>>
>> Can we please stop this?
>
> I agree.
>
sorry I don't,
unless Python is only meant for the very well educated people in encryption.

> I haven't looked at the code but the functionality that's listed is
> useful, e.g. in a Usenet client, and it's fun to play around with for
> a beginner.
I neither did look at the code,
but as a beginner with just 3 years of experience in Python,
I've tried several scrambling libs, for a quick and dirty use.
All were much too difficult, so I made my own xor-something.
Coming from Delphi, a scrambling lib is working is less than 10 minutes,
without the need of any knowledge of encryption.
I prefer Python over Delphi, but some things are made very complex in
Python.

cheers,
Stef
>
> Also, for example, Christian Heimes wrote else-thread: «Your work
> should be interesting for everybody who has read Simon Sing's "The
> Code Book: The Science of Secrecy from Ancient Egypt to Quantum"» (and
> I for one have that book).
>
>
> Cheers,
>
> - Alf

== 4 of 4 ==
Date: Tues, Feb 9 2010 3:55 pm
From: rantingrick


On Feb 9, 7:21 am, Roy Smith <r...@panix.com> wrote:
> In article <00fa27a3$0$15628$c3e8...@news.astraweb.com>,
>  Steven D'Aprano <st...@REMOVE-THIS-cybersource.com.au> wrote:

[..]

> No pig latin?

Wait a minute guys, Stevens a well known prankster and comic relief
clown around here, I think he's just shining us all on! ;o)

==============================================================================
TOPIC: Possible? Python 2.6.x and PythonWin on 64-bit Windows 7
http://groups.google.com/group/comp.lang.python/t/967738261a47aeff?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Feb 9 2010 2:49 pm
From: Sridhar Ratnakumar

On 2010-02-07, at 5:02 PM, escalation746 wrote:

> Andrej Mitrovic wrote:
>
>> Perhaps you've accidentally downloaded the wrong version of PythonWin?
>
> Erk, yes, my bad.
>
> Thanks for the quick help! Though I still wonder why the ActiveState
> build does not include this.

I just added support for PyWin32 in ActivePython 2.6 64-bit.

http://twitter.com/sridhr/status/8874549314

I should be part of next release (2.6.4.11).

-srid

==============================================================================
TOPIC: EAFP gone wrong
http://groups.google.com/group/comp.lang.python/t/fad74ab9f7cf4047?hl=en
==============================================================================

== 1 of 5 ==
Date: Tues, Feb 9 2010 2:52 pm
From: Arnaud Delobelle


Hi all,

Hi have a set of classes that represent mathematical objects which can
be represented as a string using a 'latex' method (after Knuth's famous
typesetting system). As I want to be able to typeset some builtin types as
well, I have a generic function, latex(), as follows:

def latex(val):
try:
return val.latex()
except AttributeError:
if isinstance(val, (tuple, list)):
return ", ".join(map(latex, val))
elif isinstance(val, dict):
return ", ".join(
"%s=%s" % (latex(k), latex(v))
for k, v in sorted(val.iteritems())
)
else:
return str(val)

It's EAFP and I have used this for a while with no problem. Recently I
added a new class for 'n choose r' objects, as follows:

class Choose(Expression):
def __init__(self, n, r):
self.subexprs = n, r
self.n = n
self.r = r
def calc(self, ns=None, calc=calc):
return choose(calc(self.n, ns), calc(self.r, ns))
def latex(self):
return "{%s \\choose %s}" % (latex(self.n), latex(self.k))

When I create a Choose object and try to get its latex representation,
this happens:

>>> c = Choose(5, 3)
>>> latex(c)
'<qmm.maths.expressions.Choose object at 0x17c92d0>'

This puzzled me for a bit: why is it not trying to use the latex()
method of the Choose object? I read and reread the definition of the
latex() method for a while until I found that there was a typo. Where
it says:

latex(self.k)

it should say:

latex(self.r)

Thus it triggers an AttributeError, which is exactly the kind of
exception that I am catching in the latex() function after trying
val.latex(). (Of course I could have caught this by calling c.latex()
directly but it's such a short method definition that I couldn't imagine
missing the typo!).

This means that EAFP made me hide a typo which would have been obviously
detected had I LBYLed, i.e. instead of

try:
return val.latex()
except AttributeError:
...

do

if hasattr(val, 'latex'):
return val.latex()
else:
...


So was it wrong to say it's EAFP in this case? Should I have known to
LBYL from the start? How do you decide which one to use? Up to now, I
thought it was more or less a matter of taste but now this makes me
think that at least LBYL is better than catching AttributeError.

Thanks for any guidance.

--
Arnaud


== 2 of 5 ==
Date: Tues, Feb 9 2010 3:11 pm
From: Ben Finney


Arnaud Delobelle <arnodel@googlemail.com> writes:

> As I want to be able to typeset some builtin types as well, I have a
> generic function, latex(), as follows:
>
> def latex(val):
> try:
> return val.latex()
> except AttributeError:
[…]

> It's EAFP and I have used this for a while with no problem.
[…]

> I found that there was a typo. Where it says:
>
> latex(self.k)
>
> it should say:
>
> latex(self.r)
>
> Thus it triggers an AttributeError, which is exactly the kind of
> exception that I am catching in the latex() function after trying
> val.latex(). (Of course I could have caught this by calling c.latex()
> directly but it's such a short method definition that I couldn't
> imagine missing the typo!).
>
> This means that EAFP made me hide a typo which would have been obviously
> detected had I LBYLed

The correct approach here is to reduce the operations being done in the
'try' suite to a minimum.

The fact that you're calling a function in the 'try' block obviously
opens you to the potential for an AttributeError from that function.
Since that's not what you intend to catch, you need to separate those
concerns.

def latex(val):
def make_result_in_the_absence_of_a_latex_method():
result = transmogrify(val)
return result

try:
typeset_func = val.latex
except AttributeError:
typeset_func = make_result_in_the_absence_of_a_latex_method

result = typeset_func()
return result

--
\ "Two hands working can do more than a thousand clasped in |
`\ prayer." —Anonymous |
_o__) |
Ben Finney


== 3 of 5 ==
Date: Tues, Feb 9 2010 3:22 pm
From: Malte Helmert


Arnaud Delobelle wrote:

> This means that EAFP made me hide a typo which would have been obviously
> detected had I LBYLed, i.e. instead of
>
> try:
> return val.latex()
> except AttributeError:
> ...
>
> do
>
> if hasattr(val, 'latex'):
> return val.latex()
> else:
> ...
>
>
> So was it wrong to say it's EAFP in this case?

I would say that it's not really the EAFP concept that is problematic
here, but rather that the try block encompasses more code than it
should. Generally try blocks should be as narrow as possible, i.e., they
should contain only the part where you really want to catch a potential
failure.

"return val.latex()" does two separate things that might fail: the
lookup of val.latex, and the actual method call. If I understood you
correctly, you only want to catch the AttributeError in the "val.latex"
lookup here, and hence I'd say the "correct" application of EAFP here
would be something like:

try:
foo = val.latex
except AttributeError:
...
else:
return foo()

Whether that's any better than LBYL in this particular case is of course
debatable -- one nice thing compared to your LBYL version is that it
doesn't look up val.latex twice upon success. But you could also get
that via the LBYLish:

latex_method = getattr(val, "latex")
if latex_method:
return latex_method()
...

Malte

== 4 of 5 ==
Date: Tues, Feb 9 2010 3:27 pm
From: Malte Helmert


Ben Finney wrote:

> def latex(val):
> def make_result_in_the_absence_of_a_latex_method():
> result = transmogrify(val)
> return result
>
> try:
> typeset_func = val.latex
> except AttributeError:
> typeset_func = make_result_in_the_absence_of_a_latex_method
>
> result = typeset_func()
> return result

In this particular case, where in the case of an AttributeError you want
to use a fallback callable with the same signature as the bound method
you get in case of success, I'd say getattr with a default is the nicest
approach:

def latex(val):
def make_result_in_the_absence_of_a_latex_method():
result = transmogrify(val)
return result
return getattr(val, "latex",
make_result_in_the_absence_of_a_latex_method)()


Doesn't work as nicely if you don't have
make_result_in_the_absence_of_a_latex_method's functionality bundled
into a suitable function already, though.

Malte

== 5 of 5 ==
Date: Tues, Feb 9 2010 3:49 pm
From: Matthew Barnett


Arnaud Delobelle wrote:
> Hi all,
>
> Hi have a set of classes that represent mathematical objects which can
> be represented as a string using a 'latex' method (after Knuth's famous
> typesetting system). As I want to be able to typeset some builtin types as
> well, I have a generic function, latex(), as follows:
>
> def latex(val):
> try:
> return val.latex()
> except AttributeError:
> if isinstance(val, (tuple, list)):
> return ", ".join(map(latex, val))
> elif isinstance(val, dict):
> return ", ".join(
> "%s=%s" % (latex(k), latex(v))
> for k, v in sorted(val.iteritems())
> )
> else:
> return str(val)
>
> It's EAFP and I have used this for a while with no problem. Recently I
> added a new class for 'n choose r' objects, as follows:
>
> class Choose(Expression):
> def __init__(self, n, r):
> self.subexprs = n, r
> self.n = n
> self.r = r
> def calc(self, ns=None, calc=calc):
> return choose(calc(self.n, ns), calc(self.r, ns))
> def latex(self):
> return "{%s \\choose %s}" % (latex(self.n), latex(self.k))
>
> When I create a Choose object and try to get its latex representation,
> this happens:
>
>>>> c = Choose(5, 3)
>>>> latex(c)
> '<qmm.maths.expressions.Choose object at 0x17c92d0>'
>
> This puzzled me for a bit: why is it not trying to use the latex()
> method of the Choose object? I read and reread the definition of the
> latex() method for a while until I found that there was a typo. Where
> it says:
>
> latex(self.k)
>
> it should say:
>
> latex(self.r)
>
> Thus it triggers an AttributeError, which is exactly the kind of
> exception that I am catching in the latex() function after trying
> val.latex(). (Of course I could have caught this by calling c.latex()
> directly but it's such a short method definition that I couldn't imagine
> missing the typo!).
>
> This means that EAFP made me hide a typo which would have been obviously
> detected had I LBYLed, i.e. instead of
>
> try:
> return val.latex()
> except AttributeError:
> ...
>
> do
>
> if hasattr(val, 'latex'):
> return val.latex()
> else:
> ...
>
>
> So was it wrong to say it's EAFP in this case? Should I have known to
> LBYL from the start? How do you decide which one to use? Up to now, I
> thought it was more or less a matter of taste but now this makes me
> think that at least LBYL is better than catching AttributeError.
>
> Thanks for any guidance.
>
In addition to the other replies, you should've tested the Choose class. :-)

==============================================================================
TOPIC: I've built Python, but can't figure out how to package it for windows
http://groups.google.com/group/comp.lang.python/t/98343a7bbda5e7a1?hl=en
==============================================================================

== 1 of 3 ==
Date: Tues, Feb 9 2010 2:55 pm
From: Mark Jones


Python 2.6.4 is built, and I found a bdist_wininst project and
wininst-8 project.

How do I manage to build the msi for this thing?


== 2 of 3 ==
Date: Tues, Feb 9 2010 4:14 pm
From: "Gabriel Genellina"


En Tue, 09 Feb 2010 19:55:30 -0300, Mark Jones <mark0978@gmail.com>
escribió:

> Python 2.6.4 is built, and I found a bdist_wininst project and
> wininst-8 project.
>
> How do I manage to build the msi for this thing?

See the Tools\msi directory; and look for some posts last year from Tim
Golden regarding some issues with the directory layout and other details.

--
Gabriel Genellina

== 3 of 3 ==
Date: Tues, Feb 9 2010 4:24 pm
From: Mark Jones


That was so simple, thanks.

I scanned all the folders for inst, install, setup, but since msi was
the expected output extension, I didn't see that!

On Feb 9, 6:14 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> wrote:
> En Tue, 09 Feb 2010 19:55:30 -0300, Mark Jones <mark0...@gmail.com>  
> escribió:
>
> > Python 2.6.4 is built, and I found a bdist_wininst project and
> > wininst-8 project.
>
> > How do I manage to build the msi for this thing?
>
> See the Tools\msi directory; and look for some posts last year from Tim  
> Golden regarding some issues with the directory layout and other details.
>
> --
> Gabriel Genellina


==============================================================================
TOPIC: Programing family
http://groups.google.com/group/comp.lang.python/t/9c369186368028ed?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Feb 9 2010 3:31 pm
From: Steven D'Aprano


On Tue, 09 Feb 2010 17:49:21 +0100, Bruno Desthuilliers wrote:

> On Feb 8, 2010, at 8:39 PM, AON LAZIO <aonlazio@gmail.com> wrote:
>>
>>> I have thought funny things
>>> If we think all languages are like a family
>
> Then it would be a very incestuous family fore sure.
>
>>> I could draft them like this (Python base)
>>>
>>> C is Python's Mom
>>> C++ : Dad
>
> Not that much C++ in Python, IMHO. If that's for the OO part, then the
> closer to Python's object model I can think of is javascript.

I thought that Javascript didn't even have inheritance until recently?
Like in the last year?

> Historically, Python comes from ABC, which itself comes from SETL.
>
>>> Pascal/Assembly : Grandparents
>
> Assembly ? What about binary machine code then ?-)


I'd say assembly is more like the distant answer, back when we still had
tails and lived in trees and worried about being eaten by eagles.


>>> C# : Uncle
>>> Java : Ant
>
> Interesting typo here !-)
>
> Hmmm... Python predates both C# and Java. Ok, technically speaking
> nothing prevents an uncle or aunt from being younger than their nephews,
> and I even saw the case a couple time - but that's far from being the
> common case.
>
>>> Ruby: Cousin
>>> Perl : Girlfriend
>
> Then it's kind of a very passionate love-hate relationship - bordering
> on pathological FWIW !-)

I'd say that the girlfriend is more likely Lisp or Haskell -- some of the
more functional aspects of Python have been inspired by these languages.

> Now you forgot the whole Lisp / ML heritage - most FP stuff -, and of
> course Simula and Smalltalk.

--
Steven

==============================================================================
TOPIC: Modifying Class Object
http://groups.google.com/group/comp.lang.python/t/fd36962c4970ac48?hl=en
==============================================================================

== 1 of 3 ==
Date: Tues, Feb 9 2010 3:37 pm
From: Steven D'Aprano


On Tue, 09 Feb 2010 21:04:08 +0100, Alf P. Steinbach wrote:

> You thought you cold do a bit of ad hominem attack.

That phrase you keep using, "ad hominem"... it doesn't mean what you seem
to think it means.

An ad hominem attack is not when somebody makes a criticism of you
personally. It is when somebody says something along the lines of "Don't
pay any attention to Alf, he doesn't know what he's talking about, he's a
<whatever>".

You might not like the personal criticism, but that doesn't make it
either an attack or a fallacy.


--
Steven


== 2 of 3 ==
Date: Tues, Feb 9 2010 4:06 pm
From: "Alf P. Steinbach"


* Steven D'Aprano:
> On Tue, 09 Feb 2010 21:04:08 +0100, Alf P. Steinbach wrote:
>
>> You thought you cold do a bit of ad hominem attack.
>
> That phrase you keep using, "ad hominem"... it doesn't mean what you seem
> to think it means.
>
> An ad hominem attack is not when somebody makes a criticism of you
> personally. It is when somebody says something along the lines of "Don't
> pay any attention to Alf, he doesn't know what he's talking about, he's a
> <whatever>".

<url: http://www.tfd.com/ad+hominem>
ad hominem Latin [æd ˈhɒmɪˌnɛm]
adj & adv
1. directed against a person rather than against his arguments
2. based on or appealing to emotion rather than reason Compare ad rem See also
argumentum ad hominem

> You might not like the personal criticism, but that doesn't make it
> either an attack or a fallacy.

Steve Holden attacked only at the personal level, via characterization.

In response to ...

> >> No idea. Nothing I know of can solve it [failure of article propagation].
>
> Not sure, but perhaps it's possible to mail directly to gmane?

... Steve Holden wrote:

<quote>
Is there *any* problem you don't have a fatuous answer for?
</quote>

Which doesn't have anything to do with any subject matter discussed, not even
the PS that he was replying to (which absolutely didn't warrant that description
or any negative response), but which does convey an impression of a person.

Then he wrote

<quote>
you assumed you knew better than Stephen [Hansen]
</quote>

which again is only about a person, and here about the person's motivations for
trying to help.

And there was a bit more with some collateral damage in the implications.

It's pretty dirty and yes, personal attacks are ad hominem; see above.

The ad hominem attacks that he appears to routinely engage in reflect back on
Steve Holden but the sub-threads that they invariably spawn also constitute a
high level of noise deflecting from whatever issue was discussed.

Cheers & hth. (especially the dictionary reference),

- Alf

PS: in order to recognize various forms of fallacies the following is a quite
useful resource: <url: http://www.nizkor.org/features/fallacies/>. I just typed
"fallacies" in the Firefox address bar. - DS


== 3 of 3 ==
Date: Tues, Feb 9 2010 4:23 pm
From: Ben Finney


Steven D'Aprano <steve@REMOVE-THIS-cybersource.com.au> writes:

> An ad hominem attack is not when somebody makes a criticism of you
> personally. It is when somebody says something along the lines of
> "Don't pay any attention to Alf, he doesn't know what he's talking
> about, he's a <whatever>".

In other words, a criticism of the person is only a fallacy if it is
both irrelevant to the argument *and* used to dismiss the argument.

Many criticisms are introduced not because they directly connect to the
argument, but simply because they are relevant to the demonstrated
behaviour at the time.

> You might not like the personal criticism, but that doesn't make it
> either an attack or a fallacy.

Exactly. A personal criticism can be expressed *as a criticism*, and be
valid or not without needing to be relevant to your chosen argument.
Look to the criticism on its own merits, and decide what to do about it.

--
\ "If there were not God, there would be no atheists." —G. K. |
`\ Chesterton |
_o__) |
Ben Finney

==============================================================================
TOPIC: Easter Eggs
http://groups.google.com/group/comp.lang.python/t/9ce0fe4123739cc4?hl=en
==============================================================================

== 1 of 2 ==
Date: Tues, Feb 9 2010 3:40 pm
From: "Alf P. Steinbach"


I know 3 Python Easter Eggs,

from __future__ import braces
import this
help( "antigravity" )

Are there more?


Cheers,

- Alf


== 2 of 2 ==
Date: Tues, Feb 9 2010 4:01 pm
From: rantingrick


On Feb 9, 5:40 pm, "Alf P. Steinbach" <al...@start.no> wrote:
> I know 3 Python Easter Eggs,
>
>    from __future__ import braces
>    import this
>    help( "antigravity" )
>
> Are there more?
>
> Cheers,
>
> - Alf

Oh this is just great ALF! Now what secrets will the Py-Illuminati
have to giggle about whist watching Monty Python's flying circus and
enjoying those delightfully delicious little crumpets? I very
disappointed in you sir! :'-(

PS WTF

==============================================================================
TOPIC: How to measure elapsed time under Windows?
http://groups.google.com/group/comp.lang.python/t/340c476d0357a7bd?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Feb 9 2010 3:43 pm
From: "Gabriel Genellina"


En Tue, 09 Feb 2010 13:10:56 -0300, Grant Edwards
<invalid@invalid.invalid> escribi�:

> What's the correct way to measure small periods of elapsed
> time. I've always used time.clock() in the past:
>
> However on multi-processor machines that doesn't work.
> Sometimes I get negative values for delta. According to
> google, this is due to a bug in Windows that causes the value
> of time.clock() to be different depending on which core in a
> multi-core CPU you happen to be on. [insert appropriate
> MS-bashing here]

I'm not sure you can blame MS of this issue; anyway, this patch should fix
the problem:
http://support.microsoft.com/?id=896256

> Is there another way to measure small periods of elapsed time
> (say in the 1-10ms range)?

No that I know of. QueryPerformanceCounter (the function used by
time.clock) seems to be the best timer available.

> Is there a way to lock the python process to a single core so
> that time.clock() works right?

Interactively, from the Task Manager:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/taskman_assign_process.mspx

In code, using SetProcessAffinityMask and related functions:
http://msdn.microsoft.com/en-us/library/ms686223(VS.85).aspx

--
Gabriel Genellina


==============================================================================
TOPIC: New to Python
http://groups.google.com/group/comp.lang.python/t/429d23f88afefef6?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Feb 9 2010 3:59 pm
From: Jean-Michel Pichavant


Quin wrote:
> s = f.readline()
> if 'mystring' in s: print 'foundit'
> if 'mystring' not in s: print 'not found'
> if 'mystring' in s:
> print 'processing'
>
> this generates output:
> not found
> processing
>
> so, it doesn't find the substring, but goes into processing code anyway.
>
> This is using IronPython
The code you povided works as expected.

Copy paste the exact code

JM

==============================================================================
TOPIC: Ternary plus
http://groups.google.com/group/comp.lang.python/t/05afedbd6dc66a2c?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Feb 9 2010 3:59 pm
From: "Gabriel Genellina"


En Tue, 09 Feb 2010 15:47:43 -0300, Martin Drautzburg
<Martin.Drautzburg@web.de> escribió:

> Carl Banks wrote:
>
>> You can have __add__ return a closure for the first addition, then
>> perform the operation on the second one. Example (untested):
>>
>
> That's way cool.
>
> <Flash of insight> Of course! - CURRYING!! If you can return closures
> you can do everything with just single-parameter functions.</Flash of
> insight>
>
> BTW I am not really trying to add three objects, I wanted a third object
> which controls the way the addition is done. Sort of like "/" and "//"
> which are two different ways of doing division.

See http://code.activestate.com/recipes/384122/ for another cool hack that
may help with that.

--
Gabriel Genellina


==============================================================================
TOPIC: Problem Regarding Queue
http://groups.google.com/group/comp.lang.python/t/74b045cda204e5ee?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Feb 9 2010 4:16 pm
From: Rob Williscroft


mukesh tiwari wrote in news:80fed7d5-76eb-40c8-ace1-0c35736de399
@t17g2000prg.googlegroups.com in comp.lang.python:

> Could some one please tell what is wrong with this code. I am trying
> to use Queue in this program but i am getting error

The type you appear to be trying to use is Queue.Queue which you import
with:

from Queue import Queue

http://docs.python.org/library/queue.html?highlight=queue#Queue.Queue

> Q_1=Queue()
> Q_2=Queue()
> Q_1.put(n)
> while(not Q_1.empty()):
> l=Q_1.get()
> if(rabin_miller(l)):
> Q_2.put(l)
> continue
> d=pollard(l)
> if(d==l):Q_1.put(l)
> else:

As the help page above points out also check out the deque Class:

http://docs.python.org/library/collections.html#collections.deque

Rob.

==============================================================================
TOPIC: PyCon is coming! Tomorrow, Feb. 10 is the last day for pre-conference
rates
http://groups.google.com/group/comp.lang.python/t/23b922c14b1432f0?hl=en
==============================================================================

== 1 of 1 ==
Date: Tues, Feb 9 2010 4:24 pm
From: VanL


PyCon is coming! Tomorrow (February 10th) is the last day for
pre-conference rates. You can register for PyCon online at:

<https://us.pycon.org/2010/register/>

Register while it is still Feb. 10th somewhere in the world and rest
easy in the knowledge that within 10 days you will enjoying the company
of some of the finest Python hackers in the world.

As an additional bonus, PyCon this year will be in Atlanta, making it an
ideal location for those looking for a way to escape the late winter
blizzards in the northeastern United States, or the dreary fog of the
Bay area.

See you at PyCon 2010!

==============================================================================

You received this message because you are subscribed to the Google Groups "comp.lang.python"
group.

To post to this group, visit http://groups.google.com/group/comp.lang.python?hl=en

To unsubscribe from this group, send email to comp.lang.python+unsubscribe@googlegroups.com

To change the way you get mail from this group, visit:
http://groups.google.com/group/comp.lang.python/subscribe?hl=en

To report abuse, send email explaining the problem to abuse@googlegroups.com

==============================================================================
Google Groups: http://groups.google.com/?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate