locale.getlocale() in cmd.exe vs. Idle

2014-11-10 Thread Albert-Jan Roskam
Hi,

Why do I get different output for locale.getlocale() in Idle vs. cmd.exe?

# IDLE
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on 
win32
Type "copyright", "credits" or "license()" for more information.
>>> import locale
>>> locale.getdefaultlocale()
('nl_NL', 'cp1252')
>>> locale.getlocale()
('Dutch_Netherlands', '1252')  # I need this specific notation
>>>

# cmd.exe or Ipython
C:\Users\albertjan>python
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getdefaultlocale()
('nl_NL', 'cp1252')
>>> locale.getlocale()
(None, None)

# using setlocale does work (one of these instances when I answer my own 
question while writing to the Python list)
C:\Users\albertjan>python
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, "")
'Dutch_Netherlands.1252'
>>> locale.getlocale()
('Dutch_Netherlands', '1252') 
 
Thank you!

Regards,

Albert-Jan




~~

All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a 

fresh water system, and public health, what have the Romans ever done for us?

~~ 
-- 
https://mail.python.org/mailman/listinfo/python-list


ssl error with the python mac binary

2014-11-10 Thread Paul Wiseman
Hey,

I've been using the latest mac ppc/i386 binaries from python.org
(https://www.python.org/ftp/python/2.7.8/python-2.7.8-macosx10.5.dmg).
>From what I can tell this version is linked against a pretty old
version of OpenSSL (OpenSSL 0.9.7l 28 Sep 2006) which doesn't seem to
be able to handle new sha-256 certificates.

For example I'm unable to use pip (I guess the certificate was updated recently)

Searching for gnureadline
Reading https://pypi.python.org/simple/gnureadline/
Download error on https://pypi.python.org/simple/gnureadline/: [Errno
1] _ssl.c:510: error:0D0890A1:asn1 encoding
routines:ASN1_verify:unknown message digest algorithm -- Some packages
may not be found!

Am I right in thinking this is an issue with the build of python
itself? Is there a way I can upgrade the version of OpenSSL linked
with python- or force the python build to look elsewhere for the
library? Or will I have to build my own from source?

Thanks!

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


Re: Booksigning Party at PyCon This Year!

2014-11-10 Thread michel88
My kids want to celebrate Halloween party at one of the best party venue. Can
you please help us and recommend me  best Halloween party nyc
   with
good food supplies arrangements?




--
View this message in context: 
http://python.6.x6.nabble.com/Booksigning-Party-at-PyCon-This-Year-tp935988p5077004.html
Sent from the Python - python-list mailing list archive at Nabble.com.
-- 
https://mail.python.org/mailman/listinfo/python-list


A syntax question

2014-11-10 Thread Mok-Kong Shen


I don't understand the following phenomenon. Could someone kindly 
explain it? Thanks in advance.


M. K. Shen

-

count=5

def test():
  print(count)
  if count==5:
count+=0  ### Error message if this line is active, otherwise ok.
print(count)
  return

test()
--
https://mail.python.org/mailman/listinfo/python-list


Re: A syntax question

2014-11-10 Thread alister
On Mon, 10 Nov 2014 12:07:58 +0100, Mok-Kong Shen wrote:

> I don't understand the following phenomenon. Could someone kindly
> explain it? Thanks in advance.
> 
> M. K. Shen
> 
> -
> 
> count=5
> 
> def test():
>print(count)
>if count==5:
>  count+=0  ### Error message if this line is active, otherwise ok.
>  print(count)
>return
> 
> test()
My crystal ball is currently in for repair and is not expected back in 
the foreseeable future.

What result are you getting that you don't understand & what do you 
expect?
What is the error message you get?
Post the full traceback



-- 
The POP server is out of Coke
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python script that does batch find and replace in txt files

2014-11-10 Thread alister
On Sun, 09 Nov 2014 17:49:29 -0800, Syed Khalid wrote:

> Albert,
> 
> Code is not removing  empty lines containing blank characters and not
> removing leading and trailing spaces present in each line.
> 
> 
> 
> 
> import glob, codecs, re, os
> 
> regex = re.compile(r"Age: |Sex: |House No:  ") # etc etc
> 
> for txt in glob.glob("D:/Python/source/*.txt"):
> with codecs.open(txt, encoding="utf-8") as f:
> oldlines = f.readlines()
> for i, line in enumerate(oldlines):
> if "Elector's Name:" in line:
> break
> newlines = [regex.sub("", line).strip().replace("-", "_") for line
> in oldlines[i:]]
> with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
> w.write(os.linesep.join(newlines))
> 
> Kindly do the needful

kindly read the code to understand how it is operating & then make the 
necessary changes/additions yourself comp.lang.python is no a free coding 
shop 



-- 
Nobody ever ruined their eyesight by looking at the bright side of 
something.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A syntax question

2014-11-10 Thread David Palao
> My crystal ball is currently in for repair and is not expected back in
> the foreseeable future.

Without a crystal ball, this prediction might be not well founded.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A syntax question

2014-11-10 Thread Wolfgang Maier

You may want to read:

https://docs.python.org/3/faq/programming.html?highlight=global#why-am-i-getting-an-unboundlocalerror-when-the-variable-has-a-value

from the Python docs Programming FAQ section.
It explains your problem pretty well.

As others have hinted at, always provide concrete Python error messages 
and tracebacks instead of vague descriptions.


Best,
Wolfgang


On 11/10/2014 12:07 PM, Mok-Kong Shen wrote:


I don't understand the following phenomenon. Could someone kindly
explain it? Thanks in advance.

M. K. Shen

-

count=5

def test():
   print(count)
   if count==5:
 count+=0  ### Error message if this line is active, otherwise ok.
 print(count)
   return

test()


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


Re: Python modules

2014-11-10 Thread Roy Smith
In article ,
 Steve Hayes  wrote:

> I have a book on Python that advocates dividing programs into modules, and
> importing them when needed.

Yes, this is a good idea.  Breaking your program down into modules, each 
of which does a small set of closely related things, makes it easier to 
manage.  You can test each module in isolation.  When you look at your 
version control log, you can see just the changes which apply to just 
that module.  When somebody new joins the team, they can learn about 
each module one at a time.

None of this is specific to Python.  Good software engineering practice 
is to break large applications into manageable pieces.  The vocabulary 
may change from language to language (module, package, class, library, 
dll, etc), but the basic concept is the same.

> But I understand that Python is an interpreted language, and If I wrote a
> program in Python like that, and wanted to run it on another computer, how
> would it find all the modules to import at run-time, unless I copied the whole
> directory structure over to the other computer?

Yes, exactly.  When you deploy your application someplace, you need to 
include all the things it depends on.  In the simple case of a few 
python files (say, a main program and a few modules that you're 
written), the easiest thing to do might be to just clone your source 
repository on the other machine and run it directly from that.  Another 
possibility would be to package up all the files in some sort of archive 
(tar, zip, whatever) and unpack that wherever you need it.

You will also have to set up a correct environment.  This usually means 
having an appropriate version of Python already installed, plus whatever 
third-party modules you use.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python modules

2014-11-10 Thread Chris Angelico
On Tue, Nov 11, 2014 at 12:36 AM, Roy Smith  wrote:
> Yes, exactly.  When you deploy your application someplace, you need to
> include all the things it depends on.  In the simple case of a few
> python files (say, a main program and a few modules that you're
> written), the easiest thing to do might be to just clone your source
> repository on the other machine and run it directly from that.

Even in less simple cases, that's often a good way to run things. As
long as your source repo has no large binary files in it, it'll be
reasonably small; for 400KB of source code and ~1600 commits spanning
~3 years of history, around about 2MB. When your deployment is a
source clone, it's really easy to pull changes and see what's new; and
if you ever find a bug on a deployment machine (maybe a different OS
from your usual dev system), you can make a patch right there and send
it along. There's no huge "okay, let's make a new release now"
overhead - you just keep committing (maybe pushing) changes, same as
you do any other time, and perhaps tag some commit with a version
number. Very very easy. I recommend it.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A syntax question

2014-11-10 Thread Joel Goldstick
On Mon, Nov 10, 2014 at 6:39 AM, Wolfgang Maier
 wrote:
> You may want to read:
>
> https://docs.python.org/3/faq/programming.html?highlight=global#why-am-i-getting-an-unboundlocalerror-when-the-variable-has-a-value
>
> from the Python docs Programming FAQ section.
> It explains your problem pretty well.
>
> As others have hinted at, always provide concrete Python error messages and
> tracebacks instead of vague descriptions.
>
> Best,
> Wolfgang
>
>
>
> On 11/10/2014 12:07 PM, Mok-Kong Shen wrote:
>>
>>
>> I don't understand the following phenomenon. Could someone kindly
>> explain it? Thanks in advance.
>>
>> M. K. Shen
>>
>> -
>>
>> count=5
>>
>> def test():
>>print(count)
>>if count==5:
>>  count+=0  ### Error message if this line is active, otherwise ok.
>>  print(count)
>>return
>>
>> test()
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Your problem is that count is not local.  You are reading count from
an outer scope.  When you try to increment count in your function, it
can't because it doesn't exist.
Don't use globals.

-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A syntax question

2014-11-10 Thread Grant Edwards
On 2014-11-10, David Palao  wrote:

>> My crystal ball is currently in for repair and is not expected back
>> in the foreseeable future.
>
> Without a crystal ball, this prediction might be not well founded.

That isn't a prediction.  It's an explicit statement of no prediction.
He said that it is "not expected back" rather than "expected not to be
back".  They're two different things.  The former asserts a _lack_ of
expection/prediction.  The latter asserts an expectation/prediction.

-- 
Grant Edwards   grant.b.edwardsYow! Am I in Milwaukee?
  at   
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A syntax question

2014-11-10 Thread Chris Angelico
On Tue, Nov 11, 2014 at 1:35 AM, Joel Goldstick
 wrote:
> Your problem is that count is not local.  You are reading count from
> an outer scope.  When you try to increment count in your function, it
> can't because it doesn't exist.
> Don't use globals.

False analysis, I'm afraid. The problem is that the assignment will,
in the absence of a "global" declaration, cause the name "count" to
indicate a local variable - so it won't ever be read from outer scope.
However, the OP's issue is better solved by sharing tracebacks than by
us peering into crystal balls; mine's showing a very clear image at
the moment, but it might well be incorrect.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A syntax question

2014-11-10 Thread alister
On Mon, 10 Nov 2014 14:44:53 +, Grant Edwards wrote:

> On 2014-11-10, David Palao  wrote:
> 
>>> My crystal ball is currently in for repair and is not expected back in
>>> the foreseeable future.
>>
>> Without a crystal ball, this prediction might be not well founded.
> 
> That isn't a prediction.  It's an explicit statement of no prediction.
> He said that it is "not expected back" rather than "expected not to be
> back".  They're two different things.  The former asserts a _lack_ of
> expection/prediction.  The latter asserts an expectation/prediction.

It was only a a joke maybe it was a bit to subtle   



-- 
A light wife doth make a heavy husband.
-- Wm. Shakespeare, "The Merchant of Venice"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A syntax question

2014-11-10 Thread alister
On Mon, 10 Nov 2014 14:54:55 +, alister wrote:

> On Mon, 10 Nov 2014 14:44:53 +, Grant Edwards wrote:
> 
>> On 2014-11-10, David Palao  wrote:
>> 
 My crystal ball is currently in for repair and is not expected back
 in the foreseeable future.
>>>
>>> Without a crystal ball, this prediction might be not well founded.
>> 
>> That isn't a prediction.  It's an explicit statement of no prediction.
>> He said that it is "not expected back" rather than "expected not to be
>> back".  They're two different things.  The former asserts a _lack_ of
>> expection/prediction.  The latter asserts an expectation/prediction.
> 
> It was only a a joke maybe it was a bit to subtle

I didn't expect the Spanish inquisition (Damn wish Id though of that 
before sending the last post)



-- 
One picture is worth more than ten thousand words.
-- Chinese proverb
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A syntax question

2014-11-10 Thread Peter Otten
Joel Goldstick wrote:

> On Mon, Nov 10, 2014 at 6:39 AM, Wolfgang Maier
>  wrote:
>> You may want to read:
>>
>> https://docs.python.org/3/faq/programming.html?highlight=global#why-am-i-getting-an-unboundlocalerror-when-the-variable-has-a-value
>>
>> from the Python docs Programming FAQ section.
>> It explains your problem pretty well.
>>
>> As others have hinted at, always provide concrete Python error messages
>> and tracebacks instead of vague descriptions.
>>
>> Best,
>> Wolfgang
>>
>>
>>
>> On 11/10/2014 12:07 PM, Mok-Kong Shen wrote:
>>>
>>>
>>> I don't understand the following phenomenon. Could someone kindly
>>> explain it? Thanks in advance.
>>>
>>> M. K. Shen
>>>
>>> -
>>>
>>> count=5
>>>
>>> def test():
>>>print(count)
>>>if count==5:
>>>  count+=0  ### Error message if this line is active, otherwise ok.
>>>  print(count)
>>>return
>>>
>>> test()
>>
>>
>> --
>> https://mail.python.org/mailman/listinfo/python-list
> 
> Your problem is that count is not local.  You are reading count from
> an outer scope.  When you try to increment count in your function, it
> can't because it doesn't exist.
> Don't use globals.

That's what most would expect, but the error is already triggered by the 
first

print(count)

Python decides at compile-time that count is a local variable if there is an 
assignment ("name binding") to count anywhere in the function's scope --  
even if the corresponding code will never be executed:

>>> x = 42
>>> def test():
... print(x)
... if 0: x = 42
... 
>>> test()
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in test
UnboundLocalError: local variable 'x' referenced before assignment

This is different from the class body where the global namespace is tried 
when a lookup in the local namespace fails:

>>> x = 42
>>> class A:
... print(x)
... x += 1
... 
42
>>> x
42
>>> A.x
43

Historical ;) note: In Python 2 you could trigger a similar behaviour with 
exec:

>>> def f(a):
... if a: exec "x = 42"
... print x
... 
>>> x = "global"
>>> f(True)
42
>>> f(False)
global



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


Re: A syntax question

2014-11-10 Thread Joel Goldstick
On Mon, Nov 10, 2014 at 9:54 AM, Chris Angelico  wrote:
> On Tue, Nov 11, 2014 at 1:35 AM, Joel Goldstick
>  wrote:
>> Your problem is that count is not local.  You are reading count from
>> an outer scope.  When you try to increment count in your function, it
>> can't because it doesn't exist.
>> Don't use globals.
>
> False analysis, I'm afraid. The problem is that the assignment will,
> in the absence of a "global" declaration, cause the name "count" to
> indicate a local variable - so it won't ever be read from outer scope.
> However, the OP's issue is better solved by sharing tracebacks than by
> us peering into crystal balls; mine's showing a very clear image at
> the moment, but it might well be incorrect.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list

Interesting.  Thanks for pointing that out


-- 
Joel Goldstick
http://joelgoldstick.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A syntax question

2014-11-10 Thread Grant Edwards
On 2014-11-10, alister  wrote:
> On Mon, 10 Nov 2014 14:44:53 +, Grant Edwards wrote:
>
>> On 2014-11-10, David Palao  wrote:
>> 
 My crystal ball is currently in for repair and is not expected back in
 the foreseeable future.
>>>
>>> Without a crystal ball, this prediction might be not well founded.
>> 
>> That isn't a prediction.  It's an explicit statement of no prediction.
>> He said that it is "not expected back" rather than "expected not to be
>> back".  They're two different things.  The former asserts a _lack_ of
>> expection/prediction.  The latter asserts an expectation/prediction.
>
> It was only a a joke maybe it was a bit to subtle 

I know, but in c.l.p, even jokes get nicely pednatic answers.

;)

-- 
Grant Edwards   grant.b.edwardsYow! The FALAFEL SANDWICH
  at   lands on my HEAD and I
  gmail.combecome a VEGETARIAN ...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A syntax question

2014-11-10 Thread Chris Angelico
On Tue, Nov 11, 2014 at 3:11 AM, Grant Edwards  wrote:
> I know, but in c.l.p, even jokes get nicely pednatic answers.

And in c.l.p, odd jokes get even more pedantic spelling corrections.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: [Distutils] Call for information - What assumptions can I make about Unix users' access to Windows?

2014-11-10 Thread Steve Dower
Ben Finney wrote:
> Steve Dower  writes:
>> Ben Finney wrote:
>> > The restrictions of the license terms make MS Windows an
>> > unacceptable risk on any machine I'm responsible for.
>>
>> Just out of interest, which restrictions would those be?
> 
> It has been a long time since I bothered to read any of the numerous license
> texts from Microsoft, so I can't cite specific clauses. From memory,
> unacceptable restrictions include:
> 
> * Restricting the instance to specific hardware, instead of leaving it
> up to the recipient to run the work they paid for on any hardware they
> choose.

If by "specific hardware" you mean the one-license-per-user-per-machine rule, 
you probably want to consider Windows Server, which has a more flexible license 
in this respect (or maybe not - it might just allow multiple users on one 
license/machine. I haven't checked this).

> * Forbidding reverse-engineering of the OS to see how it behaves.

Yeah, I doubt that restriction is moving anywhere. It's standard for 
closed-source software, and as I understand it's intended to legally protect 
trade secrets and patents (i.e. "we tried our hardest to keep this a trade 
secret"). I've never heard of anyone being pursued for doing it though, except 
to be offered a job working on Windows :)

> * Forbidding collaboration with other recipients to discover how the OS
> behaves.

"Other recipients" are explicitly excluded - "for use by one person at a 
time"[1] - so the rest of this point doesn't really make any sense to me.

That said, it does trigger some memories of when I was contributing to ReactOS 
years ago... is this one of their suggestions about how to avoid taint? (Or 
maybe from Wine?) Those guys have obtained their own legal advice which is 
going to be aimed at preventing a court case (not just preventing a loss - 
preventing it from happening in the first place) and so it's going to be based 
on an interpretation of the license and be more defensive than most people need 
to worry about.

> * Refusal to disclose the source code for the running OS to the
> recipient.

Again, it's part of the business and legal model. If you really want access to 
the source code, you can pay for it, but most people and businesses can't 
afford it or don't want it that badly. (There are also technical reasons why 
the source code can't easily be disclosed - how many hundreds of gigabytes of 
code are you willing to download and wade through? Yes, it's that big.)

> * Forbidding the recipient from getting their choice of vendor to make
> improvements to the OS and collaborate with other recipients on the
> improvements.

I know this used to exist, as there were a number of RT/embedded OSs available 
that were based on Windows. I think at this point they've all been absorbed 
into Microsoft though.

> * Arrogating control of the running OS to a party other than the license
> recipient, including the ability to (at Microsoft's sole discretion)
> deny applications to run, and to disable features of the OS.
> 
> * Arrogating data collection to Microsoft and undisclosed third parties,
> tracking broad classes of activity on the OS and sending the logs to a
> server not of the recipient's choosing.

It seems you fundamentally disagree with the 'licensing' model and would prefer 
an 'ownership' model. That's fine, but it's not the business model Windows 
operates under and that is unlikely to ever change. Even if I were CEO, I'd 
have a hard time changing that one :)

>> Does this prevent you from creating a VM on a cloud provider on your
>> own account?
> 
> If I need to accept restrictions such as the above, I don't see that the
> location of the instance (nor the fees charged) has any affect on these
> concerns. The risks discussed above are not mitigated.
> 
>> If the licensing is a real issue, I'm in a position where I can have a
>> positive impact on fixing it, so any info you can provide me (on- or
>> off-list) about your concerns is valuable.
> 
> Thank you for this offer, I am glad to see willingness expressed to solve 
> these
> restrictions. I hope you can achieve software freedom for all recipients of
> Microsoft operating systems.
> 
> Until then, the risk is too great to anyone to whom I have professional
> responsibilities, and my advice must continue to be that they avoid accepting
> such restrictions.

That's a fair enough position, and without people taking that stance, Linux 
(and practically every OS that's based on it) wouldn't be anywhere near as 
usable as it is today. I'm also fully aware of people with the exact opposite 
stance who give the exact opposite advice, so there's room in this world for 
all of us.

I'm sorry I can't do any better than the few responses above - these are big 
issues that run to the core of how Microsoft does business, and not only am I 
incapable of changing them, I'm nowhere near capable of fully understanding how 
it all fits together. Thanks for being willing to engage, though. It's always

Re: What does zip mean?

2014-11-10 Thread giacomo boffi

On 11/09/2014 11:44 AM, satishmlm...@gmail.com wrote:

What does zip return in the following piece of code?


To help you understanding what is the `zip` builtin,
please forget about PKZip etc and think about the
_zip fastener_ or _zipper_ in your bag or in your trousers

In the bag you have two sequences of teeth that the zipper
binds together in interlocking pairs

In your program you have two lists, whose elements `zip` returns
bound together in pairs
--
https://mail.python.org/mailman/listinfo/python-list


Re: What does zip mean?

2014-11-10 Thread Grant Edwards
On 2014-11-10, giacomo boffi  wrote:

> On 11/09/2014 11:44 AM, satishmlm...@gmail.com wrote:
>> What does zip return in the following piece of code?
>
> To help you understanding what is the `zip` builtin, please forget
> about PKZip etc and think about the _zip fastener_ or _zipper_ in
> your bag or in your trousers
>
> In the bag you have two sequences of teeth that the zipper
> binds together in interlocking pairs

No, you don't. That's not how a zipper works.  Each tooth from side A,
isn't bound with one from side B.  It's bound with _two_ of them from
side B. And each of those is in turn bound with an additional tooth
from side A, and so on...

> In your program you have two lists, whose elements `zip` returns
> bound together in pairs

What the zipper on a coat does is convert two separate sequences into
a single sequence where the members alternate between the two input
sequences.  IOW if we want to do something analogous to a zipper
fastener it should do this:

  zip([a,b,c,d,e,f],[1,2,3,4,5,6])  => [a,1,b,2,c,3,d,4,e,5,f,6]
  
Item '1' is bound equally to item 'a' and 'b'.  Item 'b' is bound
equally to item '1' and '2'.
  
-- 
Grant Edwards   grant.b.edwardsYow! I joined scientology
  at   at a garage sale!!
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


"Natural" use of cmp= in sort

2014-11-10 Thread Paddy
Hi, I do agree with 
 Raymond H. about the relative merits of cmp= and key= in 
sort/sorted, but I decided to also not let natural uses of cmp= pass silently.

In answering this question, http://stackoverflow.com/a/26850434/10562 about 
ordering subject to inequalities it seemed natural to use the cmp= argument of 
sort rather than key=.

The question is about merging given inequalities to make 1 inequality such that 
the inequalities also stays true.


Here is a copy of my code:

Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on 
win32
Type "copyright", "credits" or "license()" for more information.
>>> ineq = """f4 > f2 > f3
f4 > f1 > f3
f4 > f2 > f1
f2 > f1 > f3"""
>>> print(ineq)
f4 > f2 > f3
f4 > f1 > f3
f4 > f2 > f1
f2 > f1 > f3
>>> greater_thans, all_f = set(), set()
>>> for line in ineq.split('\n'):
tokens = line.strip().split()[::2]
for n, t1 in enumerate(tokens[:-1]):
for t2 in tokens[n+1:]:
greater_thans.add((t1, t2))
all_f.add(t1)
all_f.add(t2)


>>> sorted(all_f, cmp=lambda t1, t2: 0 if t1==t2 else 
...(1 if (t1, t2) not in greater_thans else -1))
['f4', 'f2', 'f1', 'f3']
>>> 

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


I don't read docs and don't know how to use Google. What does the print function do?

2014-11-10 Thread sohcahtoa82
Please help me this assignment is due in an hour.  Don't give me hints, just 
give me the answer because I only want a grade.  I'm not actually interested in 
learning how to program, but I know software engineers make lots of money so I 
want to be one.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "Natural" use of cmp= in sort

2014-11-10 Thread Peter Otten
Paddy wrote:

> Hi, I do agree with   
>   Raymond H. about the relative merits of cmp= and key= in
> sort/sorted, but I decided to also not let natural uses of cmp= pass
> silently.
> 
> In answering this question, http://stackoverflow.com/a/26850434/10562
> about ordering subject to inequalities it seemed natural to use the cmp=
> argument of sort rather than key=.
> 
> The question is about merging given inequalities to make 1 inequality such
> that the inequalities also stays true.
> 
> 
> Here is a copy of my code:
> 
> Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)]
> on win32 Type "copyright", "credits" or "license()" for more information.
 ineq = """f4 > f2 > f3
> f4 > f1 > f3
> f4 > f2 > f1
> f2 > f1 > f3"""
 print(ineq)
> f4 > f2 > f3
> f4 > f1 > f3
> f4 > f2 > f1
> f2 > f1 > f3
 greater_thans, all_f = set(), set()
 for line in ineq.split('\n'):
> tokens = line.strip().split()[::2]
> for n, t1 in enumerate(tokens[:-1]):
> for t2 in tokens[n+1:]:
> greater_thans.add((t1, t2))
> all_f.add(t1)
> all_f.add(t2)
> 
> 
 sorted(all_f, cmp=lambda t1, t2: 0 if t1==t2 else
> ...(1 if (t1, t2) not in greater_thans else -1))
> ['f4', 'f2', 'f1', 'f3']


I'm not sure this works. I tried:

$ cat paddy.py
ineq = """f4 > f2 > f3
f4 > f1 > f3
f4 > f2 > f1
f2 > f1 > f3
f3 > f5
"""

greater_thans = set()
all_f = set()

for line in ineq.split('\n'):
tokens = line.strip().split()[::2]
for n, t1 in enumerate(tokens[:-1]):
for t2 in tokens[n+1:]:
greater_thans.add((t1, t2))
all_f.add(t1)
all_f.add(t2)

print all_f
print greater_thans

print sorted(all_f, cmp=lambda t1, t2: 0 if t1==t2 else 
(1 if (t1, t2) not in greater_thans else -1))
$ PYTHONHASHSEED=0 python paddy.py 
set(['f1', 'f2', 'f3', 'f4', 'f5'])
set([('f1', 'f3'), ('f2', 'f1'), ('f2', 'f3'), ('f4', 'f3'), ('f4', 'f2'), 
('f4', 'f1'), ('f3', 'f5')])
['f4', 'f2', 'f1', 'f3', 'f5']
$ PYTHONHASHSEED=1 python paddy.py 
set(['f5', 'f4', 'f3', 'f2', 'f1'])
set([('f1', 'f3'), ('f2', 'f3'), ('f2', 'f1'), ('f4', 'f1'), ('f3', 'f5'), 
('f4', 'f3'), ('f4', 'f2')])
['f5', 'f4', 'f2', 'f1', 'f3']


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


Re: I don't read docs and don't know how to use Google. What does the print function do?

2014-11-10 Thread Peter Otten
sohcahto...@gmail.com wrote:

> Please help me this assignment is due in an hour.  Don't give me hints,
> just give me the answer because I only want a grade.  I'm not actually
> interested in learning how to program, but I know software engineers make
> lots of money so I want to be one.

I'm sorry I have to decline your kind offer unless you also let me do your 
dishes and walk your dog.

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


Re: "Natural" use of cmp= in sort

2014-11-10 Thread Ian Kelly
On Mon, Nov 10, 2014 at 12:19 PM, Peter Otten <__pete...@web.de> wrote:
> I'm not sure this works. I tried:

Here's a simpler failure case.

>>> ineq = """f2 > f3
... f3 > f1"""

[Previously posted code elided]

>>> greater_thans
set([('f3', 'f1'), ('f2', 'f3')])
>>> sorted(all_f, cmp=lambda t1, t2: 0 if t1==t2 else
... (1 if (t1, t2) not in greater_thans else -1))
['f1', 'f2', 'f3']

Note that the greater_thans set is missing the implication by
transitivity that f2 > f1, so the given cmp function would
inconsistently return -1 for both comparisons cmp('f1', 'f2') and
cmp('f2', 'f1').
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A syntax question

2014-11-10 Thread Roy Smith
In article ,
 Chris Angelico  wrote:

> On Tue, Nov 11, 2014 at 3:11 AM, Grant Edwards  
> wrote:
> > I know, but in c.l.p, even jokes get nicely pednatic answers.
> 
> And in c.l.p, odd jokes get even more pedantic spelling corrections.
> 
> ChrisA

a
n
d

i
m
a
g
i
n
a
r
y

j
o
k
e
s

g
e
t

r
o
t
a
t
e
d
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I don't read docs and don't know how to use Google. What does the print function do?

2014-11-10 Thread Roy Smith
In article ,
 sohcahto...@gmail.com wrote:

> Please help me this assignment is due in an hour.  Don't give me hints, just 
> give me the answer because I only want a grade.  I'm not actually interested 
> in learning how to program, but I know software engineers make lots of money 
> so I want to be one.

This post is a sine of the times.
-- 
https://mail.python.org/mailman/listinfo/python-list


Design and Build Software Engineer Opportunity

2014-11-10 Thread Charles Weitzer
My name is Charles Weitzer.  I do recruiting for machine learning teams 
worldwide. One of my clients is a startup quantitative hedge
fund located in Northern, California. The founders previous worked together at 
one of the most successful quantitative hedge funds
in the world in New York City. Now they are ready to do it again. The team 
would like to hire an extremely talented design and build
software engineer as soon as possible..  They are rebuilding their current 
trading strategy and system and also designing a new
strategy.  You could work on either or both.  The title and level of seniority 
are very flexible. Their team has made unpublished
discoveries in the field of machine learning and in other areas as well.  This 
is an opportunity to leverage these discoveries in a
real world environment.

Here is their description of the position:

**
Design and Build Software Engineer

Fast-growing quantitative trading firm seeks an exceptional software engineer. 
You will design and build new production trading
systems, machine learning infrastructure, data integration pipelines, and 
large-scale storage systems.

We seek a candidate with a proven track record of building correct, 
well-designed software, solving hard problems, and delivering
complex projects on time. You should preferably have experience designing and 
implementing fault-tolerant distributed systems.
Experience with building large-scale data infrastructure, stream processing 
systems, or latency-sensitive programs is a bonus. We
are getting big fast. Willingness to take initiative, and a gritty 
determination to productize, are essential.

Join a team that includes faculty at premier universities and PhD's from 
top-tier schools, led by the founder and CEO of a
successful Internet infrastructure startup. You will have a high impact, and 
you can expect frequent interaction with the
researchers, officers, and founders.

Compensation and benefits are highly competitive.

Qualifications:

* Experience developing with C/C++/Python/Go in a Linux environment with a 
focus on performance, concurrency, and correctness.
* Experience working in TCP/IP networking, multithreading and server 
development.
* Experience working with common Internet protocols (IP, TCP/UDP, SSL/TLS, 
HTTP, SNMP, etc.)
* Experience architecting and designing highly-available critical systems.
* Experience architecting and designing large-scale data management 
infrastructure.
* Experience working in large codebases and building modular, manageable code.

Useful Skills:

* Experience with debugging and performance profiling, including the use of 
tools such as strace, valgrind, gdb, tcpdump, etc.
* Experience with build and test automation tools.
* Experience working with well-defined change management processes.
* Has experience hunting down RDBMS performance problems, understands indexing 
options, can read an execution/explain plan, has some
experience with ORM and optimization at the code layer, etc.
* Experience with messaging queues (such as RabbitMQ and Redis), as well as 
distributed caching systems.
**
This group is currently managing a very healthy amount of capital. And their 
job description above is really just a starting point
in terms of possible responsibilities and seniority.  They can be very flexible 
for the right person.

If you are interested, let me know the best way to get in touch and we can 
discuss details.

Talk soon,

Charles Weitzer

CEO\Senior Recruiter
Charles Weitzer and Associates, Inc.
Global Financial Recruiting Services
char...@charlesweitzer.com
Voice: USA (510) 558-9182





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


Re: I don't read docs and don't know how to use Google. What does the print function do?

2014-11-10 Thread Larry Martell
On Mon, Nov 10, 2014 at 2:49 PM, Roy Smith  wrote:
> In article ,
>  sohcahto...@gmail.com wrote:
>
>> Please help me this assignment is due in an hour.  Don't give me hints, just
>> give me the answer because I only want a grade.  I'm not actually interested
>> in learning how to program, but I know software engineers make lots of money
>> so I want to be one.
>
> This post is a sine of the times.

Don't go off on a tangent.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I don't read docs and don't know how to use Google. What does the print function do?

2014-11-10 Thread Mark Lawrence

On 10/11/2014 19:24, Peter Otten wrote:

sohcahto...@gmail.com wrote:


Please help me this assignment is due in an hour.  Don't give me hints,
just give me the answer because I only want a grade.  I'm not actually
interested in learning how to program, but I know software engineers make
lots of money so I want to be one.


I'm sorry I have to decline your kind offer unless you also let me do your
dishes and walk your dog.



Quote Of The Day/Week/Month/Year/Decade/Millenium*

* please delete whichever you feel is appropriate

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: A syntax question

2014-11-10 Thread Mark Lawrence

On 10/11/2014 11:31, David Palao wrote:

My crystal ball is currently in for repair and is not expected back in
the foreseeable future.


Without a crystal ball, this prediction might be not well founded.



Especially in the future when sombody asks "Who the hell was he replying 
to?".


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: I don't read docs and don't know how to use Google. What does the print function do?

2014-11-10 Thread Ethan Furman

On 11/10/2014 11:59 AM, Larry Martell wrote:

On Mon, Nov 10, 2014 at 2:49 PM, Roy Smith  wrote:

In article ,
  sohcahto...@gmail.com wrote:


Please help me this assignment is due in an hour.  Don't give me hints, just
give me the answer because I only want a grade.  I'm not actually interested
in learning how to program, but I know software engineers make lots of money
so I want to be one.


This post is a sine of the times.


Don't go off on a tangent.


Please!  We don't need all this hyperbole!

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


Re: A syntax question

2014-11-10 Thread Tim Chase
On 2014-11-10 20:08, Mark Lawrence wrote:
> On 10/11/2014 11:31, David Palao wrote:
> >> My crystal ball is currently in for repair and is not expected
> >> back in the foreseeable future.
> >
> > Without a crystal ball, this prediction might be not well founded.
> >
> 
> Especially in the future when sombody asks "Who the hell was he
> replying to?".

That might be a concern if the mail.python.org archive failed,
and all usenet archives fell offline.  Since the threading wasn't
broken, it's a simple matter of looking at the previous message in the
thread, as referenced in the appropriate headers:

In-Reply-To: 
References:  


where that particular message can be found.  Any competent mailer or
news client should handle threading without the user even thinking
about it.

It might also be more of a concern if there was actual
question/answer content rather than just a little throw-away humor.

-tkc



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


Re: locale.getlocale() in cmd.exe vs. Idle

2014-11-10 Thread Terry Reedy

On 11/10/2014 4:22 AM, Albert-Jan Roskam wrote:

Hi,

Why do I get different output for locale.getlocale() in Idle vs. cmd.exe?

# IDLE
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on 
win32
Type "copyright", "credits" or "license()" for more information.

import locale
locale.getdefaultlocale()

('nl_NL', 'cp1252')

locale.getlocale()

('Dutch_Netherlands', '1252')  # I need this specific notation




# cmd.exe or Ipython
C:\Users\albertjan>python
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.

import locale
locale.getdefaultlocale()

('nl_NL', 'cp1252')

locale.getlocale()

(None, None)

# using setlocale does work (one of these instances when I answer my own 
question while writing to the Python list)
C:\Users\albertjan>python
Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.

import locale
locale.setlocale(locale.LC_ALL, "")

'Dutch_Netherlands.1252'

locale.getlocale()

('Dutch_Netherlands', '1252')


Idle runs code in an environment that is slightly altered from the 
standard python startup environment'.  idlelib.IOBinding has this

'''
# Try setting the locale, so that we can find out
# what encoding to use
try:
import locale
locale.setlocale(locale.LC_CTYPE, "")
'''
idlelib.run, which runs in the user-code subprocess, imports IOBinding. 
Setting LC_CTYPE is sufficient for getlocale() to not return null values.


C:\Users\Terry>python -c "import locale; print(locale.getlocale())"
(None, None)

C:\Users\Terry>python -c "import locale; 
locale.setlocale(locale.LC_CTYPE, ''); print(locale.getlocale())"

('English_United States', '1252')

--
Terry Jan Reedy

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


Re: What does zip mean?

2014-11-10 Thread Gregory Ewing

Grant Edwards wrote:


What the zipper on a coat does is convert two separate sequences into
a single sequence where the members alternate between the two input
sequences.


True, the zipper analogy isn't quite accurate. It's
hard to think of an equally concise and suggestive
name, however.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: I don't read docs and don't know how to use Google. What does the print function do?

2014-11-10 Thread Grant Edwards
On 2014-11-10, sohcahto...@gmail.com  wrote:

> Please help me this assignment is due in an hour.  Don't give me
> hints, just give me the answer because I only want a grade.  I'm not
> actually interested in learning how to program, but I know software
> engineers make lots of money so I want to be one.

That's the saddest troll I've seen in ages.

-- 
Grant Edwards   grant.b.edwardsYow! I just forgot my whole
  at   philosophy of life!!!
  gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What does zip mean?

2014-11-10 Thread Cameron Simpson

On 10Nov2014 17:19, Grant Edwards  wrote:

On 2014-11-10, giacomo boffi  wrote:

To help you understanding what is the `zip` builtin, please forget
about PKZip etc and think about the _zip fastener_ or _zipper_ in
your bag or in your trousers

In the bag you have two sequences of teeth that the zipper
binds together in interlocking pairs


No, you don't. That's not how a zipper works.  Each tooth from side A,
isn't bound with one from side B.  It's bound with _two_ of them from
side B. And each of those is in turn bound with an additional tooth
from side A, and so on...


This is true, but the analogy is still the correct one:-)

Your nitpicking will not help the OP.

Cheers,
Cameron Simpson 

WFO: the normal throttle position for Denizens, squids, and unfortunates on
50cc Honda step-throughs.
--
https://mail.python.org/mailman/listinfo/python-list


Re: I don't read docs and don't know how to use Google. What does the print function do?

2014-11-10 Thread Denis McMahon
On Mon, 10 Nov 2014 10:56:18 -0800, sohcahtoa82 wrote:

> ... I know software engineers
> make lots of money so I want to be one.

I hear that pretty boy male escorts can make even more money than 
software engineers.

They also don't need to learn how to program, which is something software 
engineers do need to do, so it sounds as if you'd be better off signing 
up with an escort agency.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I don't read docs and don't know how to use Google. What does the print function do?

2014-11-10 Thread sohcahtoa82
On Monday, November 10, 2014 1:01:05 PM UTC-8, Grant Edwards wrote:
> On 2014-11-10, sohcahtoa82  wrote:
> 
> > Please help me this assignment is due in an hour.  Don't give me
> > hints, just give me the answer because I only want a grade.  I'm not
> > actually interested in learning how to program, but I know software
> > engineers make lots of money so I want to be one.
> 
> That's the saddest troll I've seen in ages.
> 

Either you and I have a different definition of what a troll is, or your 
ability to detect parody and recognize a joke is a bit off.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I don't read docs and don't know how to use Google. What does the print function do?

2014-11-10 Thread Ian Kelly
On Mon, Nov 10, 2014 at 2:45 PM,   wrote:
> On Monday, November 10, 2014 1:01:05 PM UTC-8, Grant Edwards wrote:
>> On 2014-11-10, sohcahtoa82  wrote:
>>
>> > Please help me this assignment is due in an hour.  Don't give me
>> > hints, just give me the answer because I only want a grade.  I'm not
>> > actually interested in learning how to program, but I know software
>> > engineers make lots of money so I want to be one.
>>
>> That's the saddest troll I've seen in ages.
>>
>
> Either you and I have a different definition of what a troll is, or your 
> ability to detect parody and recognize a joke is a bit off.

The former, probably. It may have been amusing, but it was nonetheless
an off-topic post seeking to get a reaction, i.e. a troll.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ssl error with the python mac binary

2014-11-10 Thread Ned Deily
In article 
,
 Paul Wiseman  wrote:
> I've been using the latest mac ppc/i386 binaries from python.org
> (https://www.python.org/ftp/python/2.7.8/python-2.7.8-macosx10.5.dmg).
> From what I can tell this version is linked against a pretty old
> version of OpenSSL (OpenSSL 0.9.7l 28 Sep 2006) which doesn't seem to
> be able to handle new sha-256 certificates.
> 
> For example I'm unable to use pip (I guess the certificate was updated 
> recently)

Yes, the current python.org certificate does seem to cause problems for 
that version of OpenSSL, unfortunately.

> Am I right in thinking this is an issue with the build of python
> itself? Is there a way I can upgrade the version of OpenSSL linked
> with python- or force the python build to look elsewhere for the
> library? Or will I have to build my own from source?

In the Pythons from the python.org OS X installers, the Python _ssl and 
_hashlib extension modules are dynamically linked with the 
system-supplied OpenSSL libraries.  If actually running on OS X 10.5, 
one would have to rebuild _ssl.so and _hashlib.so, linking them with a 
locally-supplied version of a newer OpenSSL, since different versions of 
OpenSSL are not ABI-compatible, e.g. 0.9.7 vs 0.9.8 vs 1.0.1.  If 
running on OS X 10.6 or later, another option might be to install from 
the 64-bit/32-bit installer which is a good idea to do anyway.  For pip 
usage, a workaround would be to manually download distributions from 
PyPI (or elsewhere) using a web browser and then use pip to install from 
the downloaded file.   The next version of pip is expected to have a 
--no-check-certificate option that bypasses the certificate check at the 
cost of reduced security.  For the upcoming Python 2.7.9 release 
(planned for early December), I intend to have the Pythons in the 
python.org OS X installers use their own versions of OpenSSL and thus no 
longer depend on the now-deprecated system OpenSSL.

-- 
 Ned Deily,
 n...@acm.org

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


Re: I don't read docs and don't know how to use Google. What does the print function do?

2014-11-10 Thread MRAB

On 2014-11-10 20:16, Ethan Furman wrote:

On 11/10/2014 11:59 AM, Larry Martell wrote:

On Mon, Nov 10, 2014 at 2:49 PM, Roy Smith  wrote:

In article ,
  sohcahto...@gmail.com wrote:


Please help me this assignment is due in an hour.  Don't give me hints, just
give me the answer because I only want a grade.  I'm not actually interested
in learning how to program, but I know software engineers make lots of money
so I want to be one.


This post is a sine of the times.


Don't go off on a tangent.


Please!  We don't need all this hyperbole!


... cos it's off-topic.

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


What does (?P) pattern syntax do?

2014-11-10 Thread satishmlmlml
What does ?P and  match in the following piece of code?

re.search('(?P\w*)/(?P\w*)', '...aaa/bbb/ccc]').groups()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What does (?P) pattern syntax do?

2014-11-10 Thread Ben Finney
satishmlm...@gmail.com writes:

> What does ?P and  match in the following piece of code?

Learn about Python's regular expression features from the documentation
https://docs.python.org/3/library/re.html>.

Experiment with regular expressions using online tools such as
https://pythex.org/>.

-- 
 \   “From the moment I picked your book up until I laid it down I |
  `\was convulsed with laughter. Someday I intend reading it.” |
_o__)—Groucho Marx |
Ben Finney

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


Re: What does zip mean?

2014-11-10 Thread Terry Reedy

On 11/10/2014 3:36 PM, Cameron Simpson wrote:

On 10Nov2014 17:19, Grant Edwards  wrote:

On 2014-11-10, giacomo boffi  wrote:

To help you understanding what is the `zip` builtin, please forget
about PKZip etc and think about the _zip fastener_ or _zipper_ in
your bag or in your trousers

In the bag you have two sequences of teeth that the zipper
binds together in interlocking pairs


No, you don't. That's not how a zipper works.  Each tooth from side A,
isn't bound with one from side B.  It's bound with _two_ of them from
side B. And each of those is in turn bound with an additional tooth
from side A, and so on...


This is true, but the analogy is still the correct one:-)


Perhaps ironically in this context, zippers replaced hook-and-eye 
fastening, where the two sequences *are* matched in parallel.  "Hookless 
fastener" was one of the original names (Wikipedia).


--
Terry Jan Reedy

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


Re: "Natural" use of cmp= in sort

2014-11-10 Thread Paddy
On Monday, 10 November 2014 19:44:39 UTC, Ian  wrote:
> On Mon, Nov 10, 2014 at 12:19 PM, Peter Otten  wrote:
> > I'm not sure this works. I tried:
> 
> Here's a simpler failure case.
> 
> >>> ineq = """f2 > f3
> ... f3 > f1"""
> 
> [Previously posted code elided]
> 
> >>> greater_thans
> set([('f3', 'f1'), ('f2', 'f3')])
> >>> sorted(all_f, cmp=lambda t1, t2: 0 if t1==t2 else
> ... (1 if (t1, t2) not in greater_thans else -1))
> ['f1', 'f2', 'f3']
> 
> Note that the greater_thans set is missing the implication by
> transitivity that f2 > f1, so the given cmp function would
> inconsistently return -1 for both comparisons cmp('f1', 'f2') and
> cmp('f2', 'f1').

Thanks. I will look into this...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "Natural" use of cmp= in sort

2014-11-10 Thread Paddy
On Monday, 10 November 2014 18:45:15 UTC, Paddy  wrote:
> Hi, I do agree with   
>Raymond H. about the relative merits of cmp= and key= in 
> sort/sorted, but I decided to also not let natural uses of cmp= pass silently.
> 
> In answering this question, http://stackoverflow.com/a/26850434/10562 about 
> ordering subject to inequalities it seemed natural to use the cmp= argument 
> of sort rather than key=.
> 
> The question is about merging given inequalities to make 1 inequality such 
> that the inequalities also stays true.
> 
> 

Thanks Peter, Ian. I have modified my code to expand transitive relations and 
ask you to view it on stackoverflow via the original link (as posting code on 
newsgroups is an ugly hack).

My main reason for the post to c.l.p remains though; it seems like a *natural* 
use of the cmp= comparator function to sorted rather than using key= .

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


Re: "Natural" use of cmp= in sort

2014-11-10 Thread Ian Kelly
On Mon, Nov 10, 2014 at 8:09 PM, Paddy  wrote:
> On Monday, 10 November 2014 18:45:15 UTC, Paddy  wrote:
>> Hi, I do agree with  
>> Raymond H. about the relative merits of cmp= and key= in 
>> sort/sorted, but I decided to also not let natural uses of cmp= pass 
>> silently.
>>
>> In answering this question, http://stackoverflow.com/a/26850434/10562 about 
>> ordering subject to inequalities it seemed natural to use the cmp= argument 
>> of sort rather than key=.
>>
>> The question is about merging given inequalities to make 1 inequality such 
>> that the inequalities also stays true.
>>
>>
>
> Thanks Peter, Ian. I have modified my code to expand transitive relations and 
> ask you to view it on stackoverflow via the original link (as posting code on 
> newsgroups is an ugly hack).

You still run into trouble though if the given inequalities don't
provide enough information for a total ordering. E.g.:

>>> ' > '.join(extract_relations("""f4 > f1
... f2 > f3"""))
'f1 > f2 > f3 > f4'

By adding some debugging prints, we can see what cmp calls were made
by the sort routine and what the results were:

cmp('f2', 'f1') -> 1
cmp('f3', 'f2') -> 1
cmp('f4', 'f3') -> 1

There is no information about the relative order of f2 and f1, so the
cmp function just returns 1 there.
f2 is known to be greater than f3, so that call correctly returns 1.
There is again no information about the relative order of f4 and f3,
so it again just returns 1. However, this is inconsistent with the
first comparison that placed f1 > f2, because it implies that f1 > f4.

As you can see, giving an inconsistent cmp function to sort produces
bogus results. If you only have a partial ordering of the inputs, you
need to make sure that the cmp function you provide is consistent with
*some* total ordering.

Another issue is that your expand_transitive_relations function is I
think O(n**3 log n), which looks unattractive compared to the O(n**2)
topological sort given in the other answers. Another advantage of the
topological sort is that it will detect if the graph is cyclic (i.e.
the input data itself is inconsistent), rather than just return a
bogus output.

> My main reason for the post to c.l.p remains though; it seems like a 
> *natural* use of the cmp= comparator function to sorted rather than using 
> key= .

There are cases where a cmp function is more natural than a key
function, but for these we have the functools.cmp_to_key adapter.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-Dev] Dinamically set __call__ method

2014-11-10 Thread Ian Kelly
On Sat, Nov 8, 2014 at 3:31 PM, Gregory Ewing
 wrote:
> (BTW, I'm actually surprised that this technique makes c callable.
> There must be more going on that just "look up __call__ in the class
> object", because evaluating C.__call__ just returns the descriptor
> and doesn't invoking the descriptor mechanism.)

But of course it doesn't just lookup C.__call__, because it has to
bind the method to the instance before calling it, which means
invoking the descriptor protocol. The actual lookup is more like:

type(a).__dict__['__call__'].__get__(a, type(a))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "Natural" use of cmp= in sort

2014-11-10 Thread Paddy
On Tuesday, 11 November 2014 06:37:18 UTC, Ian  wrote:
> On Mon, Nov 10, 2014 at 8:09 PM, Paddy  wrote:
> > On Monday, 10 November 2014 18:45:15 UTC, Paddy  wrote:
> >> Hi, I do agree with
> >>   Raymond H. about the relative merits of cmp= and key= in 
> >> sort/sorted, but I decided to also not let natural uses of cmp= pass 
> >> silently.
> >>
> >> In answering this question, http://stackoverflow.com/a/26850434/10562 
> >> about ordering subject to inequalities it seemed natural to use the cmp= 
> >> argument of sort rather than key=.
> >>
> >> The question is about merging given inequalities to make 1 inequality such 
> >> that the inequalities also stays true.
> >>
> >>
> >
> > Thanks Peter, Ian. I have modified my code to expand transitive relations 
> > and ask you to view it on stackoverflow via the original link (as posting 
> > code on newsgroups is an ugly hack).
> 
> You still run into trouble though if the given inequalities don't
> provide enough information for a total ordering. E.g.:
> 
> >>> ' > '.join(extract_relations("""f4 > f1
> ... f2 > f3"""))
> 'f1 > f2 > f3 > f4'
> 
> By adding some debugging prints, we can see what cmp calls were made
> by the sort routine and what the results were:
> 
> cmp('f2', 'f1') -> 1
> cmp('f3', 'f2') -> 1
> cmp('f4', 'f3') -> 1
> 
> There is no information about the relative order of f2 and f1, so the
> cmp function just returns 1 there.
> f2 is known to be greater than f3, so that call correctly returns 1.
> There is again no information about the relative order of f4 and f3,
> so it again just returns 1. However, this is inconsistent with the
> first comparison that placed f1 > f2, because it implies that f1 > f4.
> 
> As you can see, giving an inconsistent cmp function to sort produces
> bogus results. If you only have a partial ordering of the inputs, you
> need to make sure that the cmp function you provide is consistent with
> *some* total ordering.
> 
> Another issue is that your expand_transitive_relations function is I
> think O(n**3 log n), which looks unattractive compared to the O(n**2)
> topological sort given in the other answers. Another advantage of the
> topological sort is that it will detect if the graph is cyclic (i.e.
> the input data itself is inconsistent), rather than just return a
> bogus output.
> 
> > My main reason for the post to c.l.p remains though; it seems like a 
> > *natural* use of the cmp= comparator function to sorted rather than using 
> > key= .
> 
> There are cases where a cmp function is more natural than a key
> function, but for these we have the functools.cmp_to_key adapter.

Thanks Ian. The original author states "...and it is sure that the given inputs 
will give an output, i.e., the inputs will always be valid.", which could be 
taken as meaning that all inputs are sufficient, well formed, and contain all 
relations as their first example does.

In that case, expand_transitive_relations is not even needed. Lets say it isn't 
for the sake of argument, then we are left with the direct use of cmp= versus a 
conversion to a key= function.

It seems to me that *in this case* the cmp= function naturally flows from the 
solution algorithm and that cmp_to_key is less so.

Yes, I knew that there are cases where a cmp function is more natural than key; 
the idea is to squirrel out a few. We have already made the, (well reasoned in 
my opinion), decision to go down the key= route in Python 3. I also like to 
track where my algorithms might originally map to cmp=. (It is not often).

My only other case of this type is here: 
http://stackoverflow.com/questions/15797120/can-this-cmp-function-be-better-written-as-a-key-for-sorted.
-- 
https://mail.python.org/mailman/listinfo/python-list