Re: Is it necessary to call Tk() when writing a GUI app with Tkinter?

2012-02-29 Thread Steven D'Aprano
On Wed, 29 Feb 2012 22:41:53 -0800, John Salerno wrote:

>> Yes. You must leave it out.
> 
> Now I'm reading a Tkinter reference at
> http://infohost.nmt.edu/tcc/help/pubs/tkinter/minimal-app.html and it
> has this example:
[...]

Could you please stop posting the same message twice? It's very annoying. 
There is no need to C.C. python-list because comp.lang.python is the 
mirror of the mailing list.


Thank you.



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


Re: Is it necessary to call Tk() when writing a GUI app with Tkinter?

2012-02-29 Thread John Salerno
> Yes. You must leave it out.

Now I'm reading a Tkinter reference at
http://infohost.nmt.edu/tcc/help/pubs/tkinter/minimal-app.html
and it has this example:


#!/usr/local/bin/python 
from Tkinter import *   

class Application(Frame):  
def __init__(self, master=None):
Frame.__init__(self, master)   
self.grid()
self.createWidgets()

def createWidgets(self):
self.quitButton = Button ( self, text='Quit',
command=self.quit )
self.quitButton.grid() 

app = Application()
app.master.title("Sample application") 
app.mainloop()


Is this just outdated? I don't understand why it uses quit() instead of 
destroy(). When I try this in IDLE, quit() just causes the application to hang 
(I assume because it ends the mainloop without actually closing the 
application). Or is this just a problem when using IDLE?

If the latter, which is preferable, quit or destroy?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp

2012-02-29 Thread WJ
Xah Lee wrote:

> fun example.
> 
> in-place algorithm for reversing a list in Perl, Python, Lisp
> http://xahlee.org/comp/in-place_algorithm.html
> 
> plain text follows
> 
> 
> What's “In-place Algorithm”?
> 
> Xah Lee, 2012-02-29
> 
> This page tells you what's “In-place algorithm”, using {python, perl,
> emacs lisp} code to illustrate.
> 
> Here's Wikipedia In-place algorithm excerpt:
> 
> In computer science, an in-place algorithm (or in Latin in situ) is an
> algorithm which transforms input using a data structure with a small,
> constant amount of extra storage space. The input is usually
> overwritten by the output as the algorithm executes. An algorithm
> which is not in-place is sometimes called not-in-place or out-of-
> place.
> 
> Python
> 
> Here's a python code for reversing a list. Done by creating a new
> list, NOT using in-place:
> 
> # python
> # reverse a list
> 
> list_a = ["a", "b", "c", "d", "e", "f", "g"]
> 
> list_length = len(list_a)
> list_b = [0] * list_length
> 
> for i in range(list_length):
> list_b[i] = list_a[list_length -1 - i]
> 
> print list_b
> Here's in-place algorithm for reversing a list:
> 
> # python
> # in-place algorithm for reversing a list
> 
> list_a = ["a", "b", "c", "d", "e", "f", "g"]
> 
> list_length = len(list_a)
> 
> for i in range(list_length/2):
> x = list_a[i]
> list_a[i] = list_a[ list_length -1 - i]
> list_a[ list_length -1 - i] = x
> 
> print list_a
> Perl
> 
> Here's a perl code for reversing a list. Done by creating a new list,
> NOT using in-place:
> 
> # perl
> 
> use strict;
> use Data::Dumper;
> 
> my @listA = qw(a b c d e f g);
> 
> my $listLength = scalar @listA;
> my @listB = ();
> 
> for ( my $i = 0; $i < $listLength; $i++ ) {
>  $listB[$i] = $listA[ $listLength - 1 - $i];
> }
> 
> print Dumper(\@listB);
> 
> # perl
> # in-place algorithm for reversing a list.
> 
> use strict;
> use Data::Dumper;
> use POSIX; # for “floor”
> 
> my @listA = qw(a b c d e f g);
> 
> my $listLength = scalar @listA;
> 
> for ( my $i = 0; $i < floor($listLength/2); $i++ ) {
>   my $x = $listA[$i];
>   $listA[$i] = $listA[ $listLength - 1 - $i];
>   $listA[ $listLength - 1 - $i] = $x;
> }
> 
> print Dumper(\@listA);
> __END__
> 
> emacs lisp
> 
> ;; emacs lisp
> ;; reverse a array
> 
> (setq arrayA ["a" "b" "c" "d" "e" "f" "g"])
> 
> (setq arrayLength (length arrayA))
> 
> (setq arrayB (make-vector arrayLength 0))
> 
> (dotimes (i arrayLength )
>   (aset arrayB i (aref arrayA (- (1- arrayLength) i)) )
>   )
> 
> (print (format "%S" arrayB))
> ;; emacs lisp
> ;; in-place algorithm for reversing a array
> 
> (setq arrayA ["a" "b" "c" "d" "e" "f" "g"])
> 
> (setq arrayLength (length arrayA))
> 
> (dotimes (i (floor (/ arrayLength 2)))
>   (let (x)
> (setq x (aref arrayA i))
> (aset arrayA i (aref arrayA (- (1- arrayLength) i)))
> (aset arrayA (- (1- arrayLength) i) x) ) )
> 
> (print (format "%S" arrayA))
> 

MatzLisp:

a = [2,3,5,8]
==>[2, 3, 5, 8]
a.reverse!
==>[8, 5, 3, 2]
a
==>[8, 5, 3, 2]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pyusb and microchip mcp2210 interface

2012-02-29 Thread Tim Roberts
jobattle  wrote:
>
>Has anybody out there had any experience in using the PYUSB library with
>the new Microchip MCP2210 USB to SPI chip?

It appears to the system as a HID device.  You don't need to use PyUSB --
it already has a driver.

Check libhid -- it has a Python binding.
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp

2012-02-29 Thread Evan Driscoll
On 2/29/2012 23:05, Dan Stromberg wrote:
> 
> On Wed, Feb 29, 2012 at 8:07 PM, Xah Lee  > wrote:
> 
> This page tells you what's “In-place algorithm”, using {python, perl,
> emacs lisp} code to illustrate.
> 
> Aren't in-place reversals rather non-functional?

There is one place where they're reasonably idiomatic in Lispy
languages, at least by my understanding. That occurs when you are
writing a function that returns a list and there is a natural recursive
way to build up the answer -- but backwards. The idiom then is to build
up a temporary list up backwards, then call an in-place reversal
function. (NREVERSE in Common Lisp. I thought there was a reverse! in
Scheme, but apparently not.)

This doesn't break the external view of a pure function because the list
that's being reversed is a fresh, temporary list, which is why this
idiom would even fit in pretty well in Scheme.

Evan



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it necessary to call Tk() when writing a GUI app with Tkinter?

2012-02-29 Thread John Salerno
> What exactly is the purpose of doing that? Does Tk do some extra work that a 
> simple call to Frame won't do?

More specifically, what is the benefit of doing:

root = tk.Tk()
app = Application(master=root)
app.mainloop()

as opposed to:

app = Application()
app.mainloop()

Also, in the first example, what is the difference between calling 
app.mainloop() and root.mainloop()? They both seemed to work when I ran them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it necessary to call Tk() when writing a GUI app with Tkinter?

2012-02-29 Thread John Salerno
On Wednesday, February 29, 2012 11:40:45 PM UTC-6, Terry Reedy wrote:
> On 2/29/2012 11:41 PM, John Salerno wrote:
> 
> > window? If you only want the Windows "X" button to close the window,
> > then is it okay to leave out any call to destroy()?
> 
> Yes. You must leave it out.
> 
> > the latter, then where in the code do you put the call to destroy so
> > it won't conflict with the user closing the window with the X
> > button?
> 
> See my other post of a few minutes ago for an example that now works.
> 
> -- 
> Terry Jan Reedy

When you suggested I create the root frame explicitly, you mean create a Tk 
object explicitly, as in your example, and then pass that as an argument to the 
Frame instance?

What exactly is the purpose of doing that? Does Tk do some extra work that a 
simple call to Frame won't do?


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


Re: Is it necessary to call Tk() when writing a GUI app with Tkinter?

2012-02-29 Thread John Salerno
> Yes, but i think the REAL problem is faulty code logic. Remove the
> last line "root.destroy()" and the problem is solved. Obviously the
> author does not have an in-depth knowledge of Tkinter.

The faulty code is not my own, which is part of the reason I asked the 
question. The book I'm reading (The Quick Python Book) does not use it, but I 
saw in the Python docs that it is there, under "tkinter" in the Global Module 
Docs, "24.1.2.2. A Simple Hello World Program":


from tkinter import *

class Application(Frame):
def say_hi(self):
print("hi there, everyone!")

def createWidgets(self):
self.QUIT = Button(self)
self.QUIT["text"] = "QUIT"
self.QUIT["fg"] = "red"
self.QUIT["command"] = self.quit

self.QUIT.pack({"side": "left"})

self.hi_there = Button(self)
self.hi_there["text"] = "Hello",
self.hi_there["command"] = self.say_hi

self.hi_there.pack({"side": "left"})

def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()

root = Tk()
app = Application(master=root)
app.mainloop()
root.destroy()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp

2012-02-29 Thread Xah Lee
On Feb 29, 9:01 pm, Steven D'Aprano  wrote:
> You don't need a temporary variable to swap two values in
> Python. A better way to reverse a list using more Pythonic idioms is:
>
> for i in range(len(list_a)//2):
>     list_a[i], list_a[-i-1] = list_a[-i-1], list_a[i]

forgive me sir, but i haven't been at python for a while. :)
i was, actually, refreshing myself of what little polyglot skills i
have.

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


Re: Is it necessary to call Tk() when writing a GUI app with Tkinter?

2012-02-29 Thread Terry Reedy

On 2/29/2012 11:41 PM, John Salerno wrote:


window? If you only want the Windows "X" button to close the window,
then is it okay to leave out any call to destroy()?


Yes. You must leave it out.


the latter, then where in the code do you put the call to destroy so
it won't conflict with the user closing the window with the X
button?


See my other post of a few minutes ago for an example that now works.

--
Terry Jan Reedy

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


Re: Help needed: dynamically pull data from different levels of a dict

2012-02-29 Thread Terry Reedy

On 2/29/2012 11:04 PM, Peter Rubenstein wrote:


I'd appreciate a bit of help on this problem.  I have some data that I've 
converted to a dict and I want to pull out individual pieces of it.

Simplified version--
a={'1':'a', '2':'b', '3':{4:'d'}, '5':{'6': {'7': [ {'8':'e'}, {'9':'f'} ] } } }

I'd like to be able to code something like:

data_needed = ['1', '2', '3:4', '5:6:7-8']for val in data_needed:
answer=extract_from(a,val)print answer

And get:abcde

Problem is I can't figure out what extract_from would look like, such that it 
would proceed dynamically down to the right level.  I'm open to the possibility 
that I'm not approaching this the right way.
If it helps, one member of my actual dict quoted below.  So in real life, 
something likedata_needed=['name','active-defects', 'admin-status:format', 
'description', 'traffic-statistics:input-bps']etc.

Thanks in advance,Peter

{ 'ge-0/0/0': {'active-alarms': {'interface-alarms': {'alarm-not-present': 
''}},  'active-defects': {'interface-alarms': {'alarm-not-present': ''}},  
'admin-status': {'_text': 'up', 'format': 'Enabled'},  
'current-physical-address': '00:1f:12:c0:e8:00',  'description': 
'INFRA:CROSS:ASH-64CB-1B:GE-0/0/0:',  'hardware-physical-address': 
'00:1f:12:c0:e8:00',  'if-config-flags': {'iff-snmp-traps': '', 
'internal-flags': '0x4000'},  'if-device-flags': {'ifdf-present': '', 
'ifdf-running': ''},  'if-flow-control': 'enabled',  'if-media-flags': 
{'ifmf-none': ''},  'interface-flapped': {'_text': '2010-05-23 18:20:36 UTC 
(92w3d 02:27 ago)',   'seconds': '55909644'},  'l2pt-error': 'none',  
'link-level-type': 'Ethernet',  'local-index': '171',  'logical-interface': 
{'address-family': [{'address-family-flags': {'ifff-no-redirects': '',  
'internal-flags': '0x0'}, 'address-family-name': 'inet', 
'interface-address': {'ifa-destination': '207.46.43.2/31',  'ifa-flags': 
{'ifa

f-current-preferred': '', 'ifaf-current-primary': ''},  'ifa-local': 
'207.46.43.2'}, 'mtu': '9178'},{'address-family-flags': 
{'ifff-mtu-user-conf': '',  'internal-flags': '0x1000'}, 
'address-family-name': 'mpls', 'mtu': '9174'},{'address-family-flags': 
{'ifff-none': ''}, 'address-family-name': 'multiservice', 'mtu': 
'Unlimited'}],   'description': 'INFRA:CROSS:ASH-64CB-1B:GE-0/0/0.0:',   
'encapsulation': 'ENET2',   'if-config-flags': {'iff-snmp-traps': ''},   
'local-index': '67',   'name': 'ge-0/0/0.0',   'snmp-index': '117',   
'traffic-statistics': {'input-packets': '46367422526659','output-packets': 
'35670513402384','style': 'brief'}},  'loopback': 'disabled',  'mtu': 
'9192',  'name': 'ge-0/0/0',  'oper-status': 'up',  
'physical-interface-cos-information': {'physical-interface-cos-hw-max-queues': 
'8',   'physical-interface-cos-use-max-queues': '8'},  'snmp-index': '116',  
'source-filtering': 'disabled',  'speed': '10Gbps',  't
raffic-statistics': {'input-bps': '4104358720',   'input-pps': '1059450',   
'output-bps': '232358',   'output-pps': '537816',   'style': 'brief'}},}



--
Terry Jan Reedy

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


Re: Is it necessary to call Tk() when writing a GUI app with Tkinter?

2012-02-29 Thread Terry Reedy

On 2/29/2012 10:22 PM, Rick Johnson wrote:
I do not know what book the OP is referring to,
but the current doc example is
http://docs.python.org/py3k/library/tkinter.html#a-simple-hello-world-program
My current replacement (see below) can be downloaded from the tracker:
http://bugs.python.org/issue14163


If you want to keep things simple, i would:

  1. Create the root window explicitly!


It already does that.


  2. Bind the command of the button to root.destroy
(command=root.destroy)


That works great. My current replacement example is uploaded to the 
issue http://bugs.python.org/issue14163



PS: I would highly suggest against using the "from Tkinter import *".
Instead, use "import Tkinter as tk" and prefix all module contents
with "tk.".


I have changed the example to do that. I also showed the alternate to 
initialize a widget. Here is the current version, tested on Windows 3.2.2.


import tkinter as tk

class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.pack()
self.createWidgets()

def createWidgets(self):
self.hi_there = tk.Button(self)
self.hi_there["text"] = "Hello_World\n(click_me)",
self.hi_there["command"] = self.say_hi
self.hi_there.pack({"side": "top"})

self.QUIT = tk.Button(self, text = "QUIT", fg = "red", command 
= root.destroy)

self.QUIT.pack({"side": "bottom"})

def say_hi(self):
print("hi there, everyone!")

root = tk.Tk()
app = Application(master=root)
app.mainloop()

There is a minor problem left. The hi_there Button text has underscores 
because if I use spaces instead, tk surrounds the text with {bra ces}. 
This seems bizarre. Is there any way to have Button text with spaces and 
no braces?


--
Terry Jan Reedy

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


Re: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots Af

2012-02-29 Thread Chiron
On Wed, 29 Feb 2012 23:10:48 -0500, Shmuel (Seymour J.) Metz wrote:

> ROTF,LMAO! You obviously don't have a clue as to what Mathematics means.
> Free hint: it doesn't mean Arithmetic. You're as bigoted as Xah Lee,


Hmm... maybe, instead of just ridiculing him, you could explain where he 
is mistaken.  Of course, doing that is a *LOT* harder than just calling 
him a bigot.

BTW, I happen to agree with you insofar as this poster not understanding 
the nature of mathematics.  His comment reminds me of the article, 
"Transgressing the Boundaries: Towards a Transformative Hermeneutics of 
Quantum Gravity" (http://www.physics.nyu.edu/sokal/transgress_v2/
transgress_v2_singlefile.html).  Also known as the "Sokal Hoax."

-- 
Boling's postulate:
If you're feeling good, don't worry.  You'll get over it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp

2012-02-29 Thread Dan Stromberg
On Wed, Feb 29, 2012 at 8:07 PM, Xah Lee  wrote:

> fun example.
>
> in-place algorithm for reversing a list in Perl, Python, Lisp
> http://xahlee.org/comp/in-place_algorithm.html
>
> plain text follows
> 
>
> What's “In-place Algorithm”?
>
> Xah Lee, 2012-02-29
>
> This page tells you what's “In-place algorithm”, using {python, perl,
> emacs lisp} code to illustrate.
>
> Aren't in-place reversals rather non-functional?


> Python
>
The usual way is list_a.reverse().  This is in place.

If you want to be a little weird, you could do this, but it's not in place:
list_a = list_a[::-1]

If you want to pretend you can't do this the easy ways above, you could do
this, which is in place:
length = len(list_a)
for ind in xrange(length // 2):
   other=-ind-1
   list_a[ind], list_a[other] = list_a[other], list_a[ind]

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


Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp

2012-02-29 Thread Steven D'Aprano
On Wed, 29 Feb 2012 20:07:49 -0800, Xah Lee wrote:

> Here's in-place algorithm for reversing a list:
> 
> # python
> # in-place algorithm for reversing a list
> 
> list_a = ["a", "b", "c", "d", "e", "f", "g"]
> list_length = len(list_a)
> for i in range(list_length/2):
> x = list_a[i]
> list_a[i] = list_a[ list_length -1 - i] 
> list_a[ list_length -1 - i] = x
> 
> print list_a

This is a good example of code written by somebody not very familiar with 
Python idioms. You don't need a temporary variable to swap two values in 
Python. A better way to reverse a list using more Pythonic idioms is:

for i in range(len(list_a)//2):
list_a[i], list_a[-i-1] = list_a[-i-1], list_a[i]


But the best way (even more idiomatic and much, much faster) is this:

list_a.reverse()



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


Re: Is it necessary to call Tk() when writing a GUI app with Tkinter?

2012-02-29 Thread John Salerno
> It is not necessarily to call Tk explicitly, which i think is a bug
> BTW. Sure, for simple scripts you can save one line of code but only
> at the expense of explicitness and intuitiveness. Observe
> 
> ## START CODE ##
> import Tkinter as tk
> 
> root = tk.Tk()
> root.title('Explicit Root')
> root.mainloop()
> 
> f = tk.Frame(master=None, width=100, height=100, bg='red')
> f.pack()
> f.mainloop()
> 
> b = tk.Button(master=None, text='Sloppy Coder')
> b.pack()
> b.mainloop()
> ## END CODE ##
> 
> as you can see all three examples work even though the last two don't
> explicitly create a master. The master is still there however Tkinter
> just created "magically" for you. Talk about laziness!

I'm not sure I understand which method you are advocating. It sounded like you 
said calling Tk() explicitly is a bug. I certainly would never create widgets 
without first creating a master frame, but is creating a Frame object enough, 
or should I create a Tk object and *then* a Frame object?

Also, at what point do you include the destroy method in your program, assuming 
you do not have a widget that will close the window? If you only want the 
Windows "X" button to close the window, then is it okay to leave out any call 
to destroy()? Or should always explicitly destroy it just as I explicitly 
created a Tk instance? If the latter, then where in the code do you put the 
call to destroy so it won't conflict with the user closing the window with the 
X button?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New Science Discovery: Perl Detracters Remain Idiots After A Decade!

2012-02-29 Thread Chiron
On Wed, 29 Feb 2012 23:06:42 -0500, Shmuel (Seymour J.) Metz wrote:

> In , on 02/29/2012
>at 11:43 AM, Chiron  said:
> 
>>Sure, mathematically it *should* go a particular way,
> 
> No. Mathematically it should go the way that it is defined to go. There
> is nothing in Mathematics that either requires or prohibits infix
> notation in programming languages, or even in Mathematical notation.
> 
Yes.  That (the mathematically defined way) is a particular way, is it 
not?

>>it makes sense to keep things as clear as possible.
> 
> Often infix notation with well thought out precedence is the clearest
> way to go. RPN and the like have their place, but often are difficult
> for real people to read.

However, I wasn't specifically referring to infix/postfix/prefix or 
anything of that nature.  I wasn't limiting my comment to lisp notation 
in particular, since what I said applies to any language.  I was 
referring to the placement of parentheses (or other groupings) to 
indicate to *humans* what the intended sequence of events was.  The 
problem with precedence is that it is not always clear how it will go.  
Different languages have different rules, some of which depart from the 
rules in mathematics.  Some implementations of languages are buggy in 
this regard.

Mathematically, and in any language with which I am familiar, the 
sequence:  2 + 6 / 3 will yield 4.  It is unnecessary, but harmless, to 
write this as 2 + (6 / 3).  A naive reader (or just a tired or hurried 
one) might come up with 8 / 3 if there aren't any parentheses.

Whenever there is *any* possibility of ambiguity, I see no reason not to 
clarify.  Back in the days when the way you wrote your code affected how 
it was compiled, it made sense to rely heavily on language-specific 
features, thus saving a few bytes.  With gigabyte memories, gigahertz 
clock speeds, and optimizing compilers, the pressure to try to optimize 
by hand is gone.  A few extra parentheses, or even breaking down a 
complex sequence of events into discrete, simpler ones, is no longer a 
costly luxury.  A few extra variables, if they help clarity, aren't going 
to hurt anything.  Let the machine do the grunt work.  Pamper your 
readers (which in a few weeks or months might be you) and show exactly 
what you had in mind.  That's all I'm saying.

-- 
I'd just as soon kiss a Wookie.
-- Princess Leia Organa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help needed: dynamically pull data from different levels of a dict

2012-02-29 Thread Chris Rebert
On Wed, Feb 29, 2012 at 7:56 PM, Peter Rubenstein
 wrote:
> Hi,
>
> I'd appreciate a bit of help on this problem.  I have some data that I've
> converted to a dict and I want to pull out individual pieces of it.
>
> Simplified version--
>
> a={'1':'a', '2':'b', '3':{4:'d'}, '5':{'6': {'7': [ {'8':'e'}, {'9':'f'} ] }
> } }
>
> I'd like to be able to code something like:
>
> data_needed = ['1', '2', '3:4', '5:6:7-8']
> for val in data_needed:
>     answer=extract_from(a,val)
>     print answer
>
> And get:
> a
> b
> c

"c" apparently sprung completely out of thin air...

> d
> e
>
> Problem is I can't figure out what extract_from would look like, such that
> it would proceed dynamically down to the right level.  I'm open to the
> possibility that I'm not approaching this the right way.

data_needed = ['1', '2', ('3', '4'), ('5', '6', '7', 0, '8')]

def extract_from(mapping, key_path):
current = mapping
for key in key_path:
current = current[key]
return current


I would perhaps try and restructure the data into something less
generic than nested dicts & lists, e.g. objects. You then might be
able to introduce helper querying methods.
I would also be worried about Law of Demeter violations, but
fortunately your concrete example doesn't reach any deeper than 2
levels.

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


Re: New Science Discovery: Perl Detracters Remain Idiots After A Decade!

2012-02-29 Thread Seymour J.
In , on 02/29/2012
   at 11:43 AM, Chiron  said:

>Sure, mathematically it *should* go a particular way,

No. Mathematically it should go the way that it is defined to go.
There is nothing in Mathematics that either requires or prohibits
infix notation in programming languages, or even in Mathematical
notation.

>it makes sense to keep things as clear as possible.

Often infix notation with well thought out precedence is the clearest
way to go. RPN and the like have their place, but often are difficult
for real people to read.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamt...@library.lspace.org

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


Re: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots Af

2012-02-29 Thread Seymour J.
In <87aa41k6x5@sapphire.mobileactivedefense.com>, on 02/29/2012
   at 03:15 PM, Rainer Weikusat  said:

>'mathematics' (an essentially outdated write-only programming 
>language dating back to the times when humans had to perform 
>computations themselves) 

ROTF,LMAO! You obviously don't have a clue as to what Mathematics
means. Free hint: it doesn't mean Arithmetic. You're as bigoted as Xah
Lee,

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamt...@library.lspace.org

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


lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp

2012-02-29 Thread Xah Lee
fun example.

in-place algorithm for reversing a list in Perl, Python, Lisp
http://xahlee.org/comp/in-place_algorithm.html

plain text follows


What's “In-place Algorithm”?

Xah Lee, 2012-02-29

This page tells you what's “In-place algorithm”, using {python, perl,
emacs lisp} code to illustrate.

Here's Wikipedia In-place algorithm excerpt:

In computer science, an in-place algorithm (or in Latin in situ) is an
algorithm which transforms input using a data structure with a small,
constant amount of extra storage space. The input is usually
overwritten by the output as the algorithm executes. An algorithm
which is not in-place is sometimes called not-in-place or out-of-
place.

Python

Here's a python code for reversing a list. Done by creating a new
list, NOT using in-place:

# python
# reverse a list

list_a = ["a", "b", "c", "d", "e", "f", "g"]

list_length = len(list_a)
list_b = [0] * list_length

for i in range(list_length):
list_b[i] = list_a[list_length -1 - i]

print list_b
Here's in-place algorithm for reversing a list:

# python
# in-place algorithm for reversing a list

list_a = ["a", "b", "c", "d", "e", "f", "g"]

list_length = len(list_a)

for i in range(list_length/2):
x = list_a[i]
list_a[i] = list_a[ list_length -1 - i]
list_a[ list_length -1 - i] = x

print list_a
Perl

Here's a perl code for reversing a list. Done by creating a new list,
NOT using in-place:

# perl

use strict;
use Data::Dumper;

my @listA = qw(a b c d e f g);

my $listLength = scalar @listA;
my @listB = ();

for ( my $i = 0; $i < $listLength; $i++ ) {
 $listB[$i] = $listA[ $listLength - 1 - $i];
}

print Dumper(\@listB);

# perl
# in-place algorithm for reversing a list.

use strict;
use Data::Dumper;
use POSIX; # for “floor”

my @listA = qw(a b c d e f g);

my $listLength = scalar @listA;

for ( my $i = 0; $i < floor($listLength/2); $i++ ) {
  my $x = $listA[$i];
  $listA[$i] = $listA[ $listLength - 1 - $i];
  $listA[ $listLength - 1 - $i] = $x;
}

print Dumper(\@listA);
__END__

emacs lisp

;; emacs lisp
;; reverse a array

(setq arrayA ["a" "b" "c" "d" "e" "f" "g"])

(setq arrayLength (length arrayA))

(setq arrayB (make-vector arrayLength 0))

(dotimes (i arrayLength )
  (aset arrayB i (aref arrayA (- (1- arrayLength) i)) )
  )

(print (format "%S" arrayB))
;; emacs lisp
;; in-place algorithm for reversing a array

(setq arrayA ["a" "b" "c" "d" "e" "f" "g"])

(setq arrayLength (length arrayA))

(dotimes (i (floor (/ arrayLength 2)))
  (let (x)
(setq x (aref arrayA i))
(aset arrayA i (aref arrayA (- (1- arrayLength) i)))
(aset arrayA (- (1- arrayLength) i) x) ) )

(print (format "%S" arrayA))

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


Re: Help needed: dynamically pull data from different levels of a dict

2012-02-29 Thread Peter Rubenstein

--Reposting in plan text, apologies--

Hi,

I'd appreciate a bit of help on this problem.  I have some data that I've 
converted to a dict and I want to pull out individual pieces of it.

Simplified version--
a={'1':'a', '2':'b', '3':{4:'d'}, '5':{'6': {'7': [ {'8':'e'}, {'9':'f'} ] } } }

I'd like to be able to code something like:

data_needed = ['1', '2', '3:4', '5:6:7-8']for val in data_needed:        
answer=extract_from(a,val)        print answer

And get:abcde

Problem is I can't figure out what extract_from would look like, such that it 
would proceed dynamically down to the right level.  I'm open to the possibility 
that I'm not approaching this the right way.
If it helps, one member of my actual dict quoted below.  So in real life, 
something likedata_needed=['name','active-defects', 'admin-status:format', 
'description', 'traffic-statistics:input-bps']etc.

Thanks in advance,Peter

{ 'ge-0/0/0': {'active-alarms': {'interface-alarms': {'alarm-not-present': 
''}},  'active-defects': {'interface-alarms': {'alarm-not-present': ''}},  
'admin-status': {'_text': 'up', 'format': 'Enabled'},  
'current-physical-address': '00:1f:12:c0:e8:00',  'description': 
'INFRA:CROSS:ASH-64CB-1B:GE-0/0/0:',  'hardware-physical-address': 
'00:1f:12:c0:e8:00',  'if-config-flags': {'iff-snmp-traps': '', 
'internal-flags': '0x4000'},  'if-device-flags': {'ifdf-present': '', 
'ifdf-running': ''},  'if-flow-control': 'enabled',  'if-media-flags': 
{'ifmf-none': ''},  'interface-flapped': {'_text': '2010-05-23 18:20:36 UTC 
(92w3d 02:27 ago)',   'seconds': '55909644'},  'l2pt-error': 'none',  
'link-level-type': 'Ethernet',  'local-index': '171',  'logical-interface': 
{'address-family': [{'address-family-flags': {'ifff-no-redirects': '',      
'internal-flags': '0x0'},     'address-family-name': 'inet',     
'interface-address': {'ifa-destination': '207.46.43.2/31',      'ifa-flags': 
{'ifaf-current-preferred': '', 'ifaf-current-primary': ''},      'ifa-local': 
'207.46.43.2'},     'mtu': '9178'},    {'address-family-flags': 
{'ifff-mtu-user-conf': '',      'internal-flags': '0x1000'},     
'address-family-name': 'mpls',     'mtu': '9174'},    {'address-family-flags': 
{'ifff-none': ''},     'address-family-name': 'multiservice',     'mtu': 
'Unlimited'}],   'description': 'INFRA:CROSS:ASH-64CB-1B:GE-0/0/0.0:',   
'encapsulation': 'ENET2',   'if-config-flags': {'iff-snmp-traps': ''},   
'local-index': '67',   'name': 'ge-0/0/0.0',   'snmp-index': '117',   
'traffic-statistics': {'input-packets': '46367422526659',    'output-packets': 
'35670513402384',    'style': 'brief'}},  'loopback': 'disabled',  'mtu': 
'9192',  'name': 'ge-0/0/0',  'oper-status': 'up',  
'physical-interface-cos-information': {'physical-interface-cos-hw-max-queues': 
'8',   'physical-interface-cos-use-max-queues': '8'},  'snmp-index': '116',  
'source-filtering': 'disabled',  'speed': '10Gbps',  'traffic-statistics': 
{'input-bps': '4104358720',   'input-pps': '1059450',   'output-bps': 
'232358',   'output-pps': '537816',   'style': 'brief'}},}  
   
-- 
http://mail.python.org/mailman/listinfo/python-list


Help needed: dynamically pull data from different levels of a dict

2012-02-29 Thread Peter Rubenstein

Hi,
I'd appreciate a bit of help on this problem.  I have some data that I've 
converted to a dict and I want to pull out individual pieces of it.
Simplified version--
a={'1':'a', '2':'b', '3':{4:'d'}, '5':{'6': {'7': [ {'8':'e'}, {'9':'f'} ] } } }
I'd like to be able to code something like:
data_needed = ['1', '2', '3:4', '5:6:7-8']for val in data_needed:
answer=extract_from(a,val)print answer
And get:abcde
Problem is I can't figure out what extract_from would look like, such that it 
would proceed dynamically down to the right level.  I'm open to the possibility 
that I'm not approaching this the right way.
If it helps, one member of my actual dict quoted below.  So in real life, 
something likedata_needed=['name','active-defects', 'admin-status:format', 
'description', 'traffic-statistics:input-bps']etc.
Thanks in advance,Peter
{ 'ge-0/0/0': {'active-alarms': {'interface-alarms': {'alarm-not-present': 
''}},  'active-defects': {'interface-alarms': {'alarm-not-present': ''}},  
'admin-status': {'_text': 'up', 'format': 'Enabled'},  
'current-physical-address': 'ff:ff:ff:c0:e8:00',  'description': 'XXX',  
'hardware-physical-address': 'ff:ff:ff:c0:e8:00',  'if-config-flags': 
{'iff-snmp-traps': '', 'internal-flags': '0x4000'},  'if-device-flags': 
{'ifdf-present': '', 'ifdf-running': ''},  'if-flow-control': 'enabled',  
'if-media-flags': {'ifmf-none': ''},  'interface-flapped': {'_text': 
'2010-05-23 18:20:36 UTC (92w3d 02:27 ago)',   'seconds': '55909644'},  
'l2pt-error': 'none',  'link-level-type': 'Ethernet',  'local-index': '171',  
'logical-interface': {'address-family': [{'address-family-flags': 
{'ifff-no-redirects': '',  'internal-flags': '0x0'}, 
'address-family-name': 'inet', 'interface-address': {'ifa-destination': 
'10.46.43.2/31',  'ifa-flags': {'ifaf-current-preferred': '', 
'ifaf-current-primary': ''},  'ifa-local': '10.46.43.2'}, 'mtu': 
'9178'},{'address-family-flags': {'ifff-mtu-user-conf': '',  
'internal-flags': '0x1000'}, 'address-family-name': 'mpls', 'mtu': 
'9174'},{'address-family-flags': {'ifff-none': ''}, 
'address-family-name': 'multiservice', 'mtu': 'Unlimited'}],   
'description': 'YYY',   'encapsulation': 'ENET2',   'if-config-flags': 
{'iff-snmp-traps': ''},   'local-index': '67',   'name': 'ge-0/0/0.0',   
'snmp-index': '117',   'traffic-statistics': {'input-packets': 
'46367422526659','output-packets': '35670513402384','style': 'brief'}}, 
 'loopback': 'disabled',  'mtu': '9192',  'name': 'ge-0/0/0',  'oper-status': 
'up',  'physical-interface-cos-information': 
{'physical-interface-cos-hw-max-queues': '8',   
'physical-interface-cos-use-max-queues': '8'},  'snmp-index': '116',  
'source-filtering': 'disabled',  'speed': '10Gbps',  'traffic-statistics': 
{'input-bps': '4104358720',   'input-pps': '1059450',   'output-bps': 
'232358',   'output-pps': '537816',   'style': 'brief'}},}  
   -- 
http://mail.python.org/mailman/listinfo/python-list


PyTut: Tkinter #1

2012-02-29 Thread Rick Johnson
PyTut: Tkinter #1
Graciously donated by the benevolent professor Richard Johnson

The first step to creating a Tkinter GUI is to create a blank window.
Tkinter has two classes that represent a GUI window: Toplevel and Tk.
Both the classes are basically the same, but since a GUI can have an
unlimited number of Toplevel windows, the very first window should
ALWAYS be an instance of Tk! Let's write some code.

## START CODE ##
import Tkinter as tk

root = tk.Tk()
root.mainloop()
## END CODE ##

You can probably guess what the first line does; it creates your
parent Toplevel window as an instance of Tk! The second line
"root.mainloop()" enters the event loop. Don't worry about the details
of "mainloop" at this time, just remeber that all Tkinter GUIs start
with an instance of Tk and end with a call to mainloop.

Here is the same code in a strict OOP form (For something this simple
you need not use strict OOP but eventually you will need to harness
the power of OOP!)

## START CODE ##
class App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)

app = App()
app.mainloop()
## END CODE ##

That's all folks! Keep your eyes peeled for the next glorious
installment of "PyTut: Tkinter"!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it necessary to call Tk() when writing a GUI app with Tkinter?

2012-02-29 Thread Rick Johnson
On Feb 29, 6:17 pm, Terry Reedy  wrote:
> On 2/29/2012 9:24 AM, Rick Johnson wrote:

> > On Feb 28, 11:06 pm, John Salerno  wrote:
> >> However, in the Python documentation, I see this:
>
> >> root = Tk()
> >> app = Application(master=root)
> >> app.mainloop()
> >> root.destroy()
> >> I tried the above and I got the following error:
>
> >> Traceback (most recent call last):
> >>    File "C:\Users\John\Desktop\gui.py", line 12, in
> >>      root.destroy()
> >>    File "C:\Python32\lib\tkinter\__init__.py", line 1714, in destroy
> >>      self.tk.call('destroy', self._w)
> >> _tkinter.TclError: can't invoke "destroy" command:  application has been 
> >> destroyed
>
> >> So apparently closing the window with the X button (on Windows)
>
>  >> implicitly calls the destroy() method of the root frame.
>  >> If that's the case, why does the documentation explicitly call it?
>
> I do not know if tk has changed since the example was written or if it
> was buggy from the beginning. I opened an issue to fix it.
>
> http://bugs.python.org/issue14163

"protocol" is ONLY a method of Tkinter.Tk and Tkinter.Toplevel.
Actually Toplevel and Tk are exactly the same object but Tk has an TCL
interpretor attached. Tkinter.Tk is meant to be the parent of ALL
widgets within your Tkinter GUI. Tkinter.Frame is nothing more than a
box to stuff widgets into. Tkinter.Frame IS NOT a window and therefor
it DOES NOT have window methods.

HOWEVER!

Most people start falsely believing that a Tkinter.Frame AND
Tkinter.Toplevel are the same thing; since Tkinter will "auto-
magically" pack your frame into a default Tkinter.Tk window (psst:
that's just a fancy Toplevel widget!) if you don't explicitly create
the Tk instance yourself.

>>>Slightly tangential meanderings
This inconsistency also rears it's ugly head in the dialog modules:
tkFileDialog and tkMessageBox. Both of which do not require a parent
argument to their convenience functions. Instead they allow the parent
to be OPTIONALLY passed.

Inquisitive Ivan mused: """ What's wrong with that Rick, the dialog
will still display whether a parent argument is passed or not. Heck,
even if no viable parent exists, Tkinter will create one! Tkinter is a
smart module!"""

True Ivan. However, if you dig a little deeper you will see that the
dialog created WITHOUT a parent does not function in a manner
consistent to modal dialogs; that is, owning the focus and becoming a
transient of another Toplevel window.

Also, about your second point, noobs get confused when that default
root window pops up. Then they come here and ask the same question
over and over. Can't you see the design flaw that is directly in front
of your face NOR smell the pungent odors that reeking from this
module!
<<<

Some might argue that this implicit root window creation is beneficial
for toy GUIs -- and i agree! HOWEVER, you will due enormous damage to
a neophyte's learning process. I say just force the extra line of code
and be consistent. Actually i believe SO strongly in "explicit root
window creation" that i edited the source code of my Tkinter version
to NOT allow ANY widget's master to be None.

I had written a more exhaustive "expo-say"  some time back but i
cannot remember the title.

> > Most applications will have both: user destroying, and program
> > destroying.
> > from tkMessageBox import askyesnocancel
>
> from tkinter.messagebox in 3.x

Yes, Tkinter has changed a bit in Python>=3.0, thanks for pointing
this out.

> [...snip code...]
> This works as adjusted for 3.x. I presume that a quit button or menu
> entry should also call onDestroyWindow so the effect is the same as
> clicking the outer [X] button.

Yes, but i think the REAL problem is faulty code logic. Remove the
last line "root.destroy()" and the problem is solved. Obviously the
author does not have an in-depth knowledge of Tkinter.

> I tried the same approach to fix the doc example, but unlike your class
> App(Tk), class App(Frame) does not a .protocol attribute. See the
> tracker issue for all my comments on the example.

see above comments about Tkinter.Frame, Tkinter.Toplevel, and
Tkinter.Tk ^^^

> I considered removing both the quit button and 'root.destroy' to get a
> beginning example that works properly, but as you said, having both is
> common so I would like both if the solution is not too esoteric.

If you want to keep things simple, i would:

 1. Create the root window explicitly!
 2. Bind the command of the button to root.destroy
(command=root.destroy)

I would offer better advice if i could but i have no idea where this
"book the OP is learning" is located? No one ever provided a link to
the code in question?

PS: I would highly suggest against using the "from Tkinter import *".
Instead, use "import Tkinter as tk" and prefix all module contents
with "tk.". Also, use "from Tkconstants import X, Y, X"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python scripts solution for euler projects

2012-02-29 Thread scripts examples
On Feb 29, 4:21 am, alister  wrote:
> On Tue, 28 Feb 2012 19:59:40 -0800, scripts examples wrote:
> > Got a web site setup for solving euler problems in python, perl,
> > ruby and javascript.
>
> >    Feel free to give me any feedback, thanks.
>
> Failing to give a link to the site is a pretty fundamental failure
>
> --
> Please take note:

Sorry, forgot the link.  Here it is: examplescripts.weebly.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any Advice Would Be Greatly Appreciated

2012-02-29 Thread Rodrick Brown
LinkedIn is an excellent resource for finding great candidates, However your 
problem might be because your searching for Python Developers why not hire 
great programmers and have them learn Python? 

Sent from my iPhone

On Feb 29, 2012, at 6:08 PM, Greg Harezlak  wrote:

> Hello Python Community,
> 
> I work for a mobile gaming startup in San Francisco, and we're heavily 
> staffing around skilled Python Developers. I've already submitted a job 
> posting to the Python.org website, but I was curious if anyone else had some 
> suggestions on where I could go to find some really awesome people. Thanks in 
> advance for your help.
> 
> -- 
> Greg Harezlak
> 
> 
> 
> 1 Bush Street, 7th Floor
> San Francisco, CA 94104
> 
> (T): 925.683.8578
> (E): g...@tinyco.com
> 
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is it necessary to call Tk() when writing a GUI app with Tkinter?

2012-02-29 Thread Terry Reedy

On 2/29/2012 9:24 AM, Rick Johnson wrote:

On Feb 28, 11:06 pm, John Salerno  wrote:



However, in the Python documentation, I see this:

root = Tk()
app = Application(master=root)
app.mainloop()
root.destroy()



I tried the above and I got the following error:

Traceback (most recent call last):
   File "C:\Users\John\Desktop\gui.py", line 12, in
 root.destroy()
   File "C:\Python32\lib\tkinter\__init__.py", line 1714, in destroy
 self.tk.call('destroy', self._w)
_tkinter.TclError: can't invoke "destroy" command:  application has been 
destroyed

So apparently closing the window with the X button (on Windows)

>> implicitly calls the destroy() method of the root frame.
>> If that's the case, why does the documentation explicitly call it?

I do not know if tk has changed since the example was written or if it 
was buggy from the beginning. I opened an issue to fix it.


http://bugs.python.org/issue14163


Most applications will have both: user destroying, and program
destroying.



from tkMessageBox import askyesnocancel


from tkinter.messagebox in 3.x


class App(tk.Tk):
 def __init__(self):
 tk.Tk.__init__(self)
 self.title('Close Me -->')
 self.protocol("WM_DELETE_WINDOW", self.onDestroyWindow)

 def onDestroyWindow(self):
 title = 'Confirm App Exit'
 msg = 'Save changes before exiting?'
 result = askyesnocancel(title, msg, default='cancel')
 if result is None:
 return
 elif result is True:
 print 'saving changes'
 elif result is False:
 print 'dont save changes'
 self.destroy()

if __name__ == '__main__':
 app = App()
 app.mainloop()


This works as adjusted for 3.x. I presume that a quit button or menu 
entry should also call onDestroyWindow so the effect is the same as 
clicking the outer [X] button.


I tried the same approach to fix the doc example, but unlike your class 
App(Tk), class App(Frame) does not a .protocol attribute. See the 
tracker issue for all my comments on the example.


I considered removing both the quit button and 'root.destroy' to get a 
beginning example that works properly, but as you said, having both is 
common so I would like both if the solution is not too esoteric.


--
Terry Jan Reedy

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


Re: Any Advice Would Be Greatly Appreciated

2012-02-29 Thread Philipp Hagemeister
If you're looking for skilled developers, the best way to find them is
probably to search their current work.

http://careers.stackoverflow.com/ and the more experimental
http://githire.com/ are two excellent developer-friendly solutions for that.

- Philipp

On 03/01/2012 12:08 AM, Greg Harezlak wrote:
> Hello Python Community,
> 
> I work for a mobile gaming startup in San Francisco, and we're heavily
> staffing around skilled Python Developers. I've already submitted a job
> posting to the Python.org website, but I was curious if anyone else had
> some suggestions on where I could go to find some really awesome people.
> Thanks in advance for your help.



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Any Advice Would Be Greatly Appreciated

2012-02-29 Thread Greg Harezlak
Thank you so much for the help, Philipp!

On Wed, Feb 29, 2012 at 3:48 PM, Philipp Hagemeister wrote:

> If you're looking for skilled developers, the best way to find them is
> probably to search their current work.
>
> http://careers.stackoverflow.com/ and the more experimental
> http://githire.com/ are two excellent developer-friendly solutions for
> that.
>
> - Philipp
>
> On 03/01/2012 12:08 AM, Greg Harezlak wrote:
> > Hello Python Community,
> >
> > I work for a mobile gaming startup in San Francisco, and we're heavily
> > staffing around skilled Python Developers. I've already submitted a job
> > posting to the Python.org website, but I was curious if anyone else had
> > some suggestions on where I could go to find some really awesome people.
> > Thanks in advance for your help.
>
>


-- 
*Greg Harezlak*



1 Bush Street, 7th Floor
San Francisco, CA 94104

(T): 925.683.8578
(E): g...@tinyco.com



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


Re: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade!

2012-02-29 Thread Xah Lee
i missed a point in my original post. That is, when the same operator
are adjacent. e.g. 「3 ▲ 6 ▲ 5」.

This is pointed out by Kiuhnm 〔kiuhnm03.4t.yahoo.it〕 and Tim Bradshaw.
Thanks.

though, i disagree the way they expressed it, or any sense this is
different from math.

to clarify, amend my original post, here's what's needed for binary
operator precedence:

① the symbols are ordered. (e.g. given a unique integer)

② each symbol is has either one of left-side stickness or right-side
stickness spec. (needed when adjacent symbols are the same.)

About the lisp case mentioned by Tim, e.g.  in「(f a b c)」, whether it
means 「(f (f a b) c)」 or 「(f a (f b c))」 . It is not directly relevant
to the context of my original post, because it isn't about to
operators. It's about function argument eval order. Good point,
nevertheless.

the perl doc, is still misleading, terribly bad written. Becha ass!

 Xah

On Feb 29, 4:08 am, Kiuhnm  wrote:
> On 2/29/2012 9:09, Xah Lee wrote:
>
>
> > New Science Discovery: Perl Idiots Remain Idiots After A Decade!
>
> > A excerpt from the new book 〈Modern Perl〉, just published, chapter 4
> > on “Operators”. Quote:
>
> > «The associativity of an operator governs whether it evaluates from
> > left to right or right to left. Addition is left associative, such
> > that 2 + 3 + 4 evaluates 2 + 3 first, then adds 4 to the result.
> > Exponentiation is right associative, such that 2 ** 3 ** 4 evaluates 3
> > ** 4 first, then raises 2 to the 81st power. »
>
> > LOL. Looks like the perl folks haven't changed. Fundamentals of
> > serious math got botched so badly.
>
> > Let me explain the idiocy.
>
> > It says “The associativity of an operator governs whether it evaluates
> > from left to right or right to left.”. Ok, so let's say we have 2
> > operators: a white triangle △ and a black triangle ▲. Now, by the
> > perl's teaching above, let's suppose the white triangle is “right
> > associative” and the black triangle is “left associative”. Now, look
> > at this:
>
> > 3 △ 6 ▲ 5
>
> > seems like the white and black triangles are going to draw a pistol
> > and fight for the chick 6 there. LOL.
>
> Sorry, but you're wrong and they're right.
> Associativity governs the order of evaluation of a group of operators
> *OF THE SAME PRECEDENCE*.
> If you write
>    2**3**4
> only the fact the '**' is right associative will tell you that the order is
>    2**(3**4)
> and not
>    (2**3)**4
> I remind you that 2^(3^4) != (2^3)^4.
>
> Kiuhnm
-- 
http://mail.python.org/mailman/listinfo/python-list


Any Advice Would Be Greatly Appreciated

2012-02-29 Thread Greg Harezlak
Hello Python Community,

I work for a mobile gaming startup in San Francisco, and we're heavily
staffing around skilled Python Developers. I've already submitted a job
posting to the Python.org website, but I was curious if anyone else had
some suggestions on where I could go to find some really awesome people.
Thanks in advance for your help.

-- 
*Greg Harezlak*



1 Bush Street, 7th Floor
San Francisco, CA 94104

(T): 925.683.8578
(E): g...@tinyco.com



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


Re: list comprehension question

2012-02-29 Thread Terry Reedy

On 2/29/2012 8:52 AM, Johann Spies wrote:

Please post plain text, the standard for all python.org mailing lists 
and corresponding newsgroups, and not html. Some readers print the html 
as plain text, which is confusing and obnoxious. Other like mine, do 
skip the plain text version and print the rendered html, but in this 
case, the strong background colors make your post impossible for *me* to 
read.


--
Terry Jan Reedy

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


RE: Listing children processes

2012-02-29 Thread Prasad, Ramit
>>> I've been told of by the BDFL for stating that
>>> people should not top post on any Python mailing list/news group.

>> He's the BDFL of Python, not of mailing list etiquette.

>Incorrect, I was told off for this
>http://code.activestate.com/lists/python-ideas/14065/

Why the link? If that is supposed to show how you were told off,
I do not see it. Even if it were, I still agree with Steven + Ben.

Or maybe that's what I get for trying to RTFA.

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--


-Original Message-
From: python-list-bounces+ramit.prasad=jpmorgan@python.org 
[mailto:python-list-bounces+ramit.prasad=jpmorgan@python.org] On Behalf Of 
Mark Lawrence
Sent: Tuesday, February 28, 2012 7:38 PM
To: python-list@python.org
Subject: Re: Listing children processes

On 29/02/2012 00:16, Steven D'Aprano wrote:
> On Tue, 28 Feb 2012 23:41:16 +, Mark Lawrence wrote:
>
>
>

Please don't bother apologising as I don't want to read another of your 
versions of War and Peace.

-- 
Cheers.

Mark Lawrence.

-- 
http://mail.python.org/mailman/listinfo/python-list
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Question about PyXML and python's stdlib xml

2012-02-29 Thread Prasad, Ramit
>>I'm forwarding this message to python-list, since I didn't get answer on 
>>xml-sig ML. >>Hopefully this is right list to question.
>>Please keep me in CC. Original message is below.

>>>I have concerns about PyXML and stdlib xml included directly in python.
>>>Currently (in Fedora) python is trying to import PyXML, which means 
>>>other results when you have and haven't PyXML installed.
>>>Furthermore, python's xml provides "dom", "parsers", "sax" and "etree". 
>>>PyXML provides  'dom', 'marshal', 'parsers', 'sax', 'schema', 'utils', 
>>>'xpath' and 'xslt'. Some modules are duplicated. Does PyXML provides 
>>>more functionality in those modules? Is python's xml better, same or 
>>>worse then PyXML? Anyway, python's xml is newer - is PyXML deprecated?


>Yes. It's a dead project.

>> Please keep me in CC, I'm not subscribed to the list.
>That may be the problem in the xml-sig case also.

I believe a current equivalent would be lxml.

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade!

2012-02-29 Thread namekuseijin
On Feb 29, 5:09 am, Xah Lee  wrote:
> New Science Discovery: Perl Idiots Remain Idiots After A Decade!
>
> A excerpt from the new book 〈Modern Perl〉, just published, chapter 4
> on “Operators”. Quote:
>
> «The associativity of an operator governs whether it evaluates from
> left to right or right to left. Addition is left associative, such
> that 2 + 3 + 4 evaluates 2 + 3 first, then adds 4 to the result.
> Exponentiation is right associative, such that 2 ** 3 ** 4 evaluates 3
> ** 4 first, then raises 2 to the 81st power. »
>
> LOL. Looks like the perl folks haven't changed. Fundamentals of
> serious math got botched so badly.
>
> Let me explain the idiocy.
>
> It says “The associativity of an operator governs whether it evaluates
> from left to right or right to left.”. Ok, so let's say we have 2
> operators: a white triangle △ and a black triangle ▲. Now, by the
> perl's teaching above, let's suppose the white triangle is “right
> associative” and the black triangle is “left associative”. Now, look
> at this:
>
> 3 △ 6 ▲ 5
>
> seems like the white and black triangles are going to draw a pistol
> and fight for the chick 6 there. LOL.
>
> Now, let me tell you what operator precedence is. First of all, let's
> limit ourselfs to discuss operators that are so-called binary
> operators, which, in our context, basically means single symbol
> operator that takes it's left and right side as operands. Now, each
> symbol have a “precedence”, or in other words, the set of operators
> has a order. (one easy way to think of this is that, suppose you have
> n symbols, then you give each a number, from 1 to n, as their order)
> So, when 2 symbols are placed side by side such as 「3 △ 6 ▲ 5」, the
> symbol with higher precedence wins. Another easy way to think of this
> is that each operator has a stickiness level. The higher its level, it
> more sticky it is.
>
> the problem with the perl explanations is that it's one misleading
> confusion ball. It isn't about “left/right associativity”. It isn't
> about “evaluates from left to right or right to left”. Worse, the word
> “associativity” is a math term that describe a property of algebra
> that has nothing to do with operator precedence, yet is easily
> confused with because it is a property about order of evaluation. (for
> example, the addition function is associative, meaning: 「(3+6)+5 =
> 3+(6+5)」.)
>
> compare it with this:
>
> 〈Perl & Python: Complex 
> Numbers〉http://xahlee.org/perl-python/complex_numbers.html
>
> and for a good understanding of functions and operators, see:
>
> 〈What's Function, What's 
> Operator?〉http://xahlee.org/math/function_and_operators.html

associativity of operators mean little in the Lisp world obviously, so
why was this posted here?  Sorry, perl, python and emacs folks...

BTW, it's the same in javascript: it is so such that 2 + 3 + "4" is
"54" and "2" + 3 + 4 is "234".  Blame weak typing and + overloading,
though it may be a blessing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list comprehension question

2012-02-29 Thread Chris Rebert
On Wed, Feb 29, 2012 at 5:52 AM, Johann Spies  wrote:
> I understand the following:
>
> In [79]: instansie
> instansie
> Out[79]: 'Mangosuthu Technikon'
>
> In [80]: t = [x.alt_name for x in lys]
> t = [x.alt_name for x in lys]
>
> In [81]: t
> t
> Out[81]: []
>
> In [82]: t.append(instansie)
> t.append(instansie)

Note the lack of an accompanying "Out". This means that the
expression, i.e. `t.append(instansie)`, had a result of None.
The list.append() method does *not* return the now-appended-to list.
It is a mutator method that modifies the list object in-place; per
convention, it therefore returns None to reinforce its side-effecting
nature to the user; analogous methods in other languages return void.

> In [83]: t
> t
> Out[83]: ['Mangosuthu Technikon']
>
> But then why does the following behave like this:
>
> In [84]: t = [x.alt_name for x in lys].append(instansie)
> t = [x.alt_name for x in lys].append(instansie)

You didn't do anything with .append()'s useless return value before;
here, you do, by assigning it to t.

> In [85]: t
> t
>
> In [86]: type t
> type t
> ---> type(t)
> Out[86]: NoneType

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


Re: list comprehension question

2012-02-29 Thread John Gordon
In  James Broadhead 
 writes:

> On 29 February 2012 13:52, Johann Spies  wrote:
> > In [82]: t.append(instansie)
> > t.append(instansie)
> >
> > In [83]: t
> > t
> > Out[83]: ['Mangosuthu Technikon']

> > In [84]: t = [x.alt_name for x in lys].append(instansie)
> > t = [x.alt_name for x in lys].append(instansie)
> >
> > In [85]: t
> > t
> >
> > In [86]: type t
> > type t
> > ---> type(t)
> > Out[86]: NoneType
> >

> You should note that in [82], you're not doing:
> > t = t.append(instansie)

append() modifies the list in-place.  It doesn't return anything.
(and therefore its return value is None)

>>> x = [1, 2, 3]
>>> y = x.append(4)
>>> print x
[1, 2, 3, 4]
>>> print y
None

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: list comprehension question

2012-02-29 Thread James Broadhead
On 29 February 2012 13:52, Johann Spies  wrote:
> In [82]: t.append(instansie)
> t.append(instansie)
>
> In [83]: t
> t
> Out[83]: ['Mangosuthu Technikon']

> In [84]: t = [x.alt_name for x in lys].append(instansie)
> t = [x.alt_name for x in lys].append(instansie)
>
> In [85]: t
> t
>
> In [86]: type t
> type t
> ---> type(t)
> Out[86]: NoneType
>

You should note that in [82], you're not doing:
> t = t.append(instansie)

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


list comprehension question

2012-02-29 Thread Johann Spies
I understand the following:

In [79]: instansie
instansie
Out[79]: 'Mangosuthu Technikon'

In [80]: t = [x.alt_name for x in lys]
t = [x.alt_name for x in lys]

In [81]: t
t
Out[81]: []

In [82]: t.append(instansie)
t.append(instansie)

In [83]: t
t
Out[83]: ['Mangosuthu Technikon']

But then why does the following behave like this:

In [84]: t = [x.alt_name for x in lys].append(instansie)
t = [x.alt_name for x in lys].append(instansie)

In [85]: t
t

In [86]: type t
type t
---> type(t)
Out[86]: NoneType

Regards
Johann
-- 
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade!

2012-02-29 Thread Kiuhnm

On 2/29/2012 16:15, Rainer Weikusat wrote:

[...] 'mathematics' (an essentially
outdated write-only programming language dating back to the times
when humans had to perform computations themselves) [...]


Theoretical Computer Science is a branch of mathematics. Are you saying 
it is outdated?


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


Re: On u'Unicode string literals' reintroduction (Py3)

2012-02-29 Thread jmfauth
On 29 fév, 14:45, jmfauth  wrote:
> For those who do not know:
> The u'' string literal trick has never worked in Python 2.
>
> >>> sys.version
>
> '2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]'>>> print 
> u'Un oeuf à zéro EURO uro'
>
> Un  uf à zéro  uro
>
>
>
> jmf


Sorry, I just wanted to show a small example.
I semms Google as "changed" again.

You should read (2nd attempt)
u'Un œuf à zéro €' with the *correct* typed glyphs 'LATIN SMALL
LIGATURE OE'
in œuf and 'EURO SIGN' in '€uro'.

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


Re: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade!

2012-02-29 Thread Rainer Weikusat
Xah Lee  writes:
> A excerpt from the new book 〈Modern Perl〉, just published, chapter 4
> on “Operators”. Quote:
>
> «The associativity of an operator governs whether it evaluates from
> left to right or right to left. Addition is left associative, such
> that 2 + 3 + 4 evaluates 2 + 3 first, then adds 4 to the result.
> Exponentiation is right associative, such that 2 ** 3 ** 4 evaluates 3
> ** 4 first, then raises 2 to the 81st power. »
>
> LOL. Looks like the perl folks haven't changed. Fundamentals of
> serious math got botched so badly.
>
> Let me explain the idiocy.
>
> It says “The associativity of an operator governs whether it evaluates
> from left to right or right to left.”. Ok, so let's say we have 2
> operators: a white triangle △ and a black triangle ▲. Now, by the
> perl's teaching above, let's suppose the white triangle is “right
> associative” and the black triangle is “left associative”. Now, look
> at this:
>
> 3 △ 6 ▲ 5
>
> seems like the white and black triangles are going to draw a pistol
> and fight for the chick 6 there. LOL.

As the perlop manpage would have told you,

Operator associativity defines what happens if a sequence of the same
operators is used one after another

Since this is not the case in your example, it doesn't seem to be
applicable here. Also, the Perl I'm aware doesn't have 'white
triangle' and 'black triangle' operators and it also doesn't have
operators of equal precedence and different associativity. It can't,
actually, since there would be no way to evaluate an expression like
the mock one you invented above. Lastly, that something happens to be 
in one way or another way in the completely arbitrary set of rules and
conventions commonly referred to as 'mathematics' (an essentially
outdated write-only programming language dating back to the times
when humans had to perform computations themselves) doesn't mean it is
of any relevance anywhere else just because of this, no matter how
dear it might be to lots of people.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: On u'Unicode string literals' (Py3)

2012-02-29 Thread Dave Angel

Just who are you replying to?

On 02/29/2012 08:45 AM, jmfauth wrote:

For those who do not know:
The u'' string literal trick has never worked in Python 2.



No trick there.  If you have something explicit to say, then say it.

sys.version

'2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]'


Why then does the subject line say Py3 ?


print u'Un oeuf à zéro EURO uro'


You're testing three things here, so there's no telling which might be 
wrong.  Your source encoding, the implicit str() conversion for unicode, 
and the particular terminal you're printing it on.  It'd be amazing if 
all three were right, unless you're on Linux.



Un  uf à zéro  uro
jmf



--

DaveA

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


Re: Fwd: Question about PyXML and python's stdlib xml

2012-02-29 Thread Stefan Behnel
Roman Rakus, 29.02.2012 15:33:
> I'm forwarding this message to python-list, since I didn't get answer on
> xml-sig ML

I didn't see a message from you on that list.


> I have concerns about PyXML and stdlib xml included directly in python.
> Currently (in Fedora) python is trying to import PyXML, which means
> other results when you have and haven't PyXML installed.

What kind of "other results"?


> Furthermore, python's xml provides "dom", "parsers", "sax" and "etree".
> PyXML provides  'dom', 'marshal', 'parsers', 'sax', 'schema', 'utils',
> 'xpath' and 'xslt'. Some modules are duplicated. Does PyXML provides
> more functionality in those modules? Is python's xml better, same or
> worse then PyXML?

PyXML was meant as an extension and hooked into the stdlib XML support.
That's only one of the reasons why it's broken now.


> Anyway, python's xml is newer - is PyXML deprecated?

Yes. It's a dead project.


> Please keep me in CC, I'm not subscribed to the list.

That may be the problem in the xml-sig case also.

Stefan

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


Re: Listing children processes

2012-02-29 Thread Giampaolo Rodolà
Il 28 febbraio 2012 22:47, Arnaud Delobelle  ha scritto:
> On 28 February 2012 21:39, Mihai Badoiu  wrote:
>> On Tue, Feb 28, 2012 at 4:35 PM, Chris Rebert  wrote:
>>>
>>> On Tue, Feb 28, 2012 at 10:33 AM, Mihai Badoiu  wrote:
>>> > I'm trying to compute the total CPU load of an external process and it's
>>> > children.  (so I cannot use resource.getrusage)  For the load of the
>>> > process
>>> > I can just grab it from /proc/X/stat.  How do I get the CPU load of the
>>> > children processes?  Is there an easy way to get a list of the children
>>> > processes?
>>>
>>> http://code.google.com/p/psutil/
>>>
>>> Cheers,
>>> Chris
>
>> Looked at that before.  psutil doesn't do children.

Yes, it does:

>>> import psutil, os
>>> p = psutil.Process(os.getpid())
>>> p.get_children()
[ ... list of process children ... ]
>>>


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


Fwd: Question about PyXML and python's stdlib xml

2012-02-29 Thread Roman Rakus
I'm forwarding this message to python-list, since I didn't get answer on 
xml-sig ML. Hopefully this is right list to question.

Please keep me in CC. Original message is below.

RR

 Original Message 
Subject:Question about PyXML and python's stdlib xml
Date:   Mon, 27 Feb 2012 16:51:00 +0100
From:   Roman Rakus 
To: xml-...@python.org



Hi,
I have concerns about PyXML and stdlib xml included directly in python.
Currently (in Fedora) python is trying to import PyXML, which means
other results when you have and haven't PyXML installed.
Furthermore, python's xml provides "dom", "parsers", "sax" and "etree".
PyXML provides  'dom', 'marshal', 'parsers', 'sax', 'schema', 'utils',
'xpath' and 'xslt'. Some modules are duplicated. Does PyXML provides
more functionality in those modules? Is python's xml better, same or
worse then PyXML? Anyway, python's xml is newer - is PyXML deprecated?

Please keep me in CC, I'm not subscribed to the list.

RR

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


Re: Is it necessary to call Tk() when writing a GUI app with Tkinter?

2012-02-29 Thread Rick Johnson
On Feb 28, 11:06 pm, John Salerno  wrote:
> The book I'm reading about using Tkinter only does this when creating the 
> top-level window:
>
> app = Application()
> app.mainloop()
>
> and of course the Application class has subclassed the tkinter.Frame class.
>
> However, in the Python documentation, I see this:
>
> root = Tk()
> app = Application(master=root)
> app.mainloop()
> root.destroy()
>
> Is it necessary to explicitly call Tk(), then pass that result as an argument 
> for the Application call? Is it also necessary to call destroy() on the root 
> frame?

It is not necessarily to call Tk explicitly, which i think is a bug
BTW. Sure, for simple scripts you can save one line of code but only
at the expense of explicitness and intuitiveness. Observe

## START CODE ##
import Tkinter as tk

root = tk.Tk()
root.title('Explicit Root')
root.mainloop()

f = tk.Frame(master=None, width=100, height=100, bg='red')
f.pack()
f.mainloop()

b = tk.Button(master=None, text='Sloppy Coder')
b.pack()
b.mainloop()
## END CODE ##

as you can see all three examples work even though the last two don't
explicitly create a master. The master is still there however Tkinter
just created "magically" for you. Talk about laziness!

> I tried the above and I got the following error:
>
> Traceback (most recent call last):
>   File "C:\Users\John\Desktop\gui.py", line 12, in 
>     root.destroy()
>   File "C:\Python32\lib\tkinter\__init__.py", line 1714, in destroy
>     self.tk.call('destroy', self._w)
> _tkinter.TclError: can't invoke "destroy" command:  application has been 
> destroyed
>
> So apparently closing the window with the X button (on Windows) implicitly 
> calls the destroy() method of the root frame. If that's the case, why does 
> the documentation explicitly call it?

Because the documentation is FLAWED! Please provide links to this
"documentation" so we can post it on the Wall Of Shame.

> Furthermore, I pasted the exact example from the documentation into IDLE and 
> ran it, and I also go the same error, so the example in the documentation 
> doesn't even work.

IDLE uses the same Python as the command line so naturally it will
throw the same error. ;-)

> So is it sufficient simply to create an Application instance, use mainloop, 
> and then handle the closing of the window elsewhere in the program (such as a 
> widget calling the destroy method on-click, or just letting the X button do 
> it)?

Most applications will have both: user destroying, and program
destroying. Again, your example is FLAWED. Here is a simplified
example:

## START CODE ##

from tkMessageBox import askyesnocancel

class App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.title('Close Me -->')
self.protocol("WM_DELETE_WINDOW", self.onDestroyWindow)

def onDestroyWindow(self):
title = 'Confirm App Exit'
msg = 'Save changes before exiting?'
result = askyesnocancel(title, msg, default='cancel')
if result is None:
return
elif result is True:
print 'saving changes'
elif result is False:
print 'dont save changes'
self.destroy()

if __name__ == '__main__':
app = App()
app.mainloop()

## END CODE ##
-- 
http://mail.python.org/mailman/listinfo/python-list


Looking for a simple, generic Python module to provide a secure web service

2012-02-29 Thread David Shi
We are looking for a very simple, generic Python module to
provide a secure web service.   Ideally,
it can be put onto the computer and make it available via IIS.
 
Off we go.
 
Your help will be gratefully received.
 
Regards.
 
David-- 
http://mail.python.org/mailman/listinfo/python-list


On u'Unicode string literals' (Py3)

2012-02-29 Thread jmfauth
For those who do not know:
The u'' string literal trick has never worked in Python 2.

>>> sys.version
'2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]'
>>> print u'Un oeuf à zéro EURO uro'
Un  uf à zéro  uro
>>>

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


building GNU debugger (was: Re: Python-list Digest, Vol 101, Issue 164)

2012-02-29 Thread Ulrich Eckhardt

Three things up front:
1. Do not reply to digests. If you want to only read, you can use the
digests, but they are not usable for replying, because it is completely
unclear where in a discussion you are entering and what you are relating
your answers to.
2. Do not start new threads by using the reply button. Your reply
contains the message ID of the message you're replying to even if you
delete any trace from the body. Better email on news clients will
display your message associated with the one you replied to, although
there is no relation at all. This is also called stealing threads.
3. Pick a meaningful subject. My attitude is generally that if you don't 
have time to pick a subject line, I don't have time to help you.


Generally, getting help is easier if you did your job. Make sure you 
read and understand Eric S. Raymond's essay on asking questions the

smart way.


Am 29.02.2012 12:43, schrieb Shambhu Rajak:

I want building GNU debugger for mingw.


Doesn't mingw come with GDB or at least have a GDB package? However,
this has nothing to do with Python.



Need the GDB to support python How should I go about it?


You don't need GDB in order to "support python", which has its own 
debugger. What is it that you're trying to achieve? See also mentioned 
essay on how to ask good questions.




This message contains information that may be privileged [...]


If you can, please remove this.


Good luck!

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


Re: python scripts solution for euler projects

2012-02-29 Thread alister
On Tue, 28 Feb 2012 19:59:40 -0800, scripts examples wrote:

> Got a web site setup for solving euler problems in python, perl,
> ruby and javascript.
> 
>Feel free to give me any feedback, thanks.

Failing to give a link to the site is a pretty fundamental failure



-- 
Please take note:
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade!

2012-02-29 Thread Devin Jeanpierre
On Wed, Feb 29, 2012 at 6:43 AM, Chiron  wrote:
> Personally, I think this whole issue of precedence in a programming
> language is over-rated.  It seems to me that grouping of any non-trivial
> set of calculations should be done so as to remove any possible confusion
> as to intent.

Some languages do this. e.g. all lisps.

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


Re: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade!

2012-02-29 Thread Kiuhnm

On 2/29/2012 9:09, Xah Lee wrote:

New Science Discovery: Perl Idiots Remain Idiots After A Decade!

A excerpt from the new book 〈Modern Perl〉, just published, chapter 4
on “Operators”. Quote:

«The associativity of an operator governs whether it evaluates from
left to right or right to left. Addition is left associative, such
that 2 + 3 + 4 evaluates 2 + 3 first, then adds 4 to the result.
Exponentiation is right associative, such that 2 ** 3 ** 4 evaluates 3
** 4 first, then raises 2 to the 81st power. »

LOL. Looks like the perl folks haven't changed. Fundamentals of
serious math got botched so badly.

Let me explain the idiocy.

It says “The associativity of an operator governs whether it evaluates
from left to right or right to left.”. Ok, so let's say we have 2
operators: a white triangle △ and a black triangle ▲. Now, by the
perl's teaching above, let's suppose the white triangle is “right
associative” and the black triangle is “left associative”. Now, look
at this:

3 △ 6 ▲ 5

seems like the white and black triangles are going to draw a pistol
and fight for the chick 6 there. LOL.


Sorry, but you're wrong and they're right.
Associativity governs the order of evaluation of a group of operators 
*OF THE SAME PRECEDENCE*.

If you write
  2**3**4
only the fact the '**' is right associative will tell you that the order is
  2**(3**4)
and not
  (2**3)**4
I remind you that 2^(3^4) != (2^3)^4.

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


CrowdFinch Technologies

2012-02-29 Thread CrowdFinch
CrowdFinch Technologies is a leading professional custom web design
and web development company specialized in Outsourced Web Development
Services, Mobile Application Development, Web design, SEO Services.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade!

2012-02-29 Thread Chiron
On Wed, 29 Feb 2012 00:09:16 -0800, Xah Lee wrote:

Personally, I think this whole issue of precedence in a programming 
language is over-rated.  It seems to me that grouping of any non-trivial 
set of calculations should be done so as to remove any possible confusion 
as to intent.  It is one more obstacle to accidental errors in logic, 
where you intend one thing, possibly overlook precedence, and get a 
strange result.

Sure, mathematically it *should* go a particular way, and any programming 
language *should* follow that.  Still... they don't, and since they don't 
it makes more sense to be really obvious what you meant to do.

As someone pointed out, a programming language is for humans; computers 
don't need them.  That being the case, it makes sense to keep things as 
clear as possible.

-- 
It's OKAY -- I'm an INTELLECTUAL, too.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Python-list Digest, Vol 101, Issue 164

2012-02-29 Thread Shambhu Rajak
Hi,
I want building GNU debugger for mingw.
Need the GDB to support python 
How should I go about it?

Thanks,
Shambhu

This message contains information that may be privileged or confidential and is 
the property of the KPIT Cummins Infosystems Ltd. It is intended only for the 
person to whom it is addressed. If you are not the intended recipient, you are 
not authorized to read, print, retain copy, disseminate, distribute, or use 
this message or any part thereof. If you receive this message in error, please 
notify the sender immediately and delete all copies of this message. KPIT 
Cummins Infosystems Ltd. does not accept any liability for virus infected mails.


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


Re: use CTRL+L for clearing the screen

2012-02-29 Thread Ben Finney
Jabba Laci  writes:

> I would like to add a clear screen feature, which would be activated
> with CTRL+L. How to do that?
> Another thing: raw_input waits until  but I'd like to clear the
> screen at the moment when CTRL+L is pressed.

That sounds like a job for the standard library ‘readline’ module
http://docs.python.org/library/readline.html>, an interface to the
widely-used C library of the same name on free operating systems.

-- 
 \ “We demand rigidly defined areas of doubt and uncertainty!” |
  `\—Vroomfondel, _The Hitch-Hiker's Guide To The Galaxy_, Douglas |
_o__)Adams |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why this fails??

2012-02-29 Thread Dave Angel

On 02/29/2012 04:07 AM, Smiley 4321 wrote:

Why below fails -


#!/usr/bin/python

import pickle

class MyClass(object):

 Field1 = None
 Field2 = None

 def __init__(self, dictionary):
 self.__dict__.update(dictionary)

 my_List = {'Field1': 'Apple', 'Field2': 'Orange'}
 myInst = MyClass(my_List)

 with open('/tmp/readfile.pkl', 'wb') as f:
  pickle.dump(myInst, f)


with below error messges -

$ ./pickleClassWrite.py
Traceback (most recent call last):
   File "./pickleClassWrite.py", line 5, in
 class MyClass(object):
   File "./pickleClassWrite.py", line 14, in MyClass
 myInst = MyClass(my_List)
NameError: name 'MyClass' is not defined
---



The reason for the error is that you're trying to use the class (by 
name) before its definition is complete.


The cause is that the code starting with the line "my_list = {Field1... 
" should have been dedented to be at top-level.  You don't want those 
last 4 lines to be inside the class.






--

DaveA

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


Re: Problem using s.strip() to remove leading whitespace in .csv file

2012-02-29 Thread Dave Angel

On 02/29/2012 04:05 AM, Guillaume Chorn wrote:

Thanks, the suggestion

print name.decode("utf-8").strip()

worked like a charm.  When I did the print repr(name) I got exactly what
you predicted.  I'm not yet sure what all of this means, but I'm going to
read this  in the hopes of
finding out.  Anyway thanks again for the help!


cheers,
Guillaume



What it means is that the character before the name was not a space 
character, but some Unicode variant of space.  Peter figured that out, 
not I.  It also means that you were using the incorrect decoder for the 
way the file was encoded and written out.


Are you creating that csv file with some Windows app, or with Python?  
You should look at it with a hex viewer to see if there are other 
surprises waiting for you in there.  For example, you might also need 
the same kind of solution if there are quotes (or an apostrophe) 
anywhere in the file. Or if someone's address uses an umlaut.


Generally, it's better to clean up cruft at the source, when possible.  
And if that means the file has to be stored in utf-8, you should decode 
the whole file that way, and then deal with it as unicode.






--

DaveA

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


use CTRL+L for clearing the screen

2012-02-29 Thread Jabba Laci
Hi,

I'm working on an interactive script. With raw_input user input is
read and the script produces some output and offers the prompt again.
I would like to add a clear screen feature, which would be activated
with CTRL+L. How to do that?
Another thing: raw_input waits until  but I'd like to clear the
screen at the moment when CTRL+L is pressed.

The script should be self-contained, thus I'd like to solve it by
using the standard library only.

Thanks,

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


Re: Problem using s.strip() to remove leading whitespace in .csv file

2012-02-29 Thread Guillaume Chorn
Thanks, the suggestion

print name.decode("utf-8").strip()

worked like a charm.  When I did the print repr(name) I got exactly what
you predicted.  I'm not yet sure what all of this means, but I'm going to
read this  in the hopes of
finding out.  Anyway thanks again for the help!


cheers,
Guillaume
-- 
http://mail.python.org/mailman/listinfo/python-list


Why this fails??

2012-02-29 Thread Smiley 4321
Why below fails -


#!/usr/bin/python

import pickle

class MyClass(object):

Field1 = None
Field2 = None

def __init__(self, dictionary):
self.__dict__.update(dictionary)

my_List = {'Field1': 'Apple', 'Field2': 'Orange'}
myInst = MyClass(my_List)

with open('/tmp/readfile.pkl', 'wb') as f:
 pickle.dump(myInst, f)


with below error messges -

$ ./pickleClassWrite.py
Traceback (most recent call last):
  File "./pickleClassWrite.py", line 5, in 
class MyClass(object):
  File "./pickleClassWrite.py", line 14, in MyClass
myInst = MyClass(my_List)
NameError: name 'MyClass' is not defined
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem using s.strip() to remove leading whitespace in .csv file

2012-02-29 Thread Karim

Le 29/02/2012 10:01, Karim a écrit :

Le 29/02/2012 09:25, Guillaume Chorn a écrit :

Hello All,

I have a .csv file that I created by copying and pasting a list of 
all the players in the NBA with their respective teams and positions 
(http://sports.yahoo.com/nba/players?type=lastname&first=1&query=&go=GO! 
).  
Unfortunately, when I do this I have no choice but to include a 
single leading whitespace character for each name.  I'd like to 
compare this list of names to another list (also in .csv format but 
in a different file) using a simple Python script, but in order to do 
that I need to strip the leading whitespace from all of the names or 
none of them will match the names in the second list.  However, when 
I try to do this as follows:


positions = open('/home/guillaume/Documents/playerpos.csv')

for line in positions:
info = line.split(',')
name = info[0]
name = name.strip()
print name #to examine the effect of name.strip()

I keep getting all of the names with the leading whitespace character 
NOT removed (for example: " Jeff Adrien". Why is this happening?


The following is a sample of the .csv file (the one I'm trying to 
remove the whitespace from) opened in gedit, the built-in Ubuntu text 
editor:


 Jeff Adrien,SF,Houston Rockets
 Arron Afflalo,SG,Denver Nuggets
 Maurice Ager,GF,Minnesota Timberwolves
 Blake Ahearn,PG,Los Angeles Clippers
 Alexis Ajinca,FC,Toronto Raptors
 Solomon Alabi,C,Toronto Raptors
 Cole Aldrich,C,Oklahoma City Thunder
 LaMarcus Aldridge,FC,Portland Trail Blazers
 Joe Alexander,SF,New Orleans Hornets
 Lavoy Allen,FC,Philadelphia 76ers
 Malik Allen,FC,Orlando Magic
 Ray Allen,SG,Boston Celtics
 Tony Allen,GF,Memphis Grizzlies
 Lance Allred,C,Indiana Pacers
 Rafer Alston,PG,Miami Heat

Any help with this seemingly simple but maddening issue would be much 
appreciated.


thanks,
Guillaume






Use csv module instead of parsing yourself the csv file:

import csv

reader = csv.Reader(open("file.csv"))

for row in reader:
  for key in row:
print("key=", key, " value=", row[key])


Code above not tested but should work.

Cheers
Karim


Just a correction use a dictionary like csv reader:

*reader = csv.DictReader(open("file.csv"))*

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


Re: Problem using s.strip() to remove leading whitespace in .csv file

2012-02-29 Thread Karim

Le 29/02/2012 09:25, Guillaume Chorn a écrit :

Hello All,

I have a .csv file that I created by copying and pasting a list of all 
the players in the NBA with their respective teams and positions 
(http://sports.yahoo.com/nba/players?type=lastname&first=1&query=&go=GO! 
).  
Unfortunately, when I do this I have no choice but to include a single 
leading whitespace character for each name.  I'd like to compare this 
list of names to another list (also in .csv format but in a different 
file) using a simple Python script, but in order to do that I need to 
strip the leading whitespace from all of the names or none of them 
will match the names in the second list.  However, when I try to do 
this as follows:


positions = open('/home/guillaume/Documents/playerpos.csv')

for line in positions:
info = line.split(',')
name = info[0]
name = name.strip()
print name #to examine the effect of name.strip()

I keep getting all of the names with the leading whitespace character 
NOT removed (for example: " Jeff Adrien". Why is this happening?


The following is a sample of the .csv file (the one I'm trying to 
remove the whitespace from) opened in gedit, the built-in Ubuntu text 
editor:


 Jeff Adrien,SF,Houston Rockets
 Arron Afflalo,SG,Denver Nuggets
 Maurice Ager,GF,Minnesota Timberwolves
 Blake Ahearn,PG,Los Angeles Clippers
 Alexis Ajinca,FC,Toronto Raptors
 Solomon Alabi,C,Toronto Raptors
 Cole Aldrich,C,Oklahoma City Thunder
 LaMarcus Aldridge,FC,Portland Trail Blazers
 Joe Alexander,SF,New Orleans Hornets
 Lavoy Allen,FC,Philadelphia 76ers
 Malik Allen,FC,Orlando Magic
 Ray Allen,SG,Boston Celtics
 Tony Allen,GF,Memphis Grizzlies
 Lance Allred,C,Indiana Pacers
 Rafer Alston,PG,Miami Heat

Any help with this seemingly simple but maddening issue would be much 
appreciated.


thanks,
Guillaume






Use csv module instead of parsing yourself the csv file:

import csv

reader = csv.Reader(open("file.csv"))

for row in reader:
  for key in row:
print("key=", key, " value=", row[key])


Code above not tested but should work.

Cheers
Karim

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


Re: Problem using s.strip() to remove leading whitespace in .csv file

2012-02-29 Thread Peter Otten
Guillaume Chorn wrote:

> Hello All,
> 
> I have a .csv file that I created by copying and pasting a list of all the
> players in the NBA with their respective teams and positions (
> http://sports.yahoo.com/nba/players?type=lastname&first=1&query=&go=GO!).
> Unfortunately, when I do this I have no choice but to include a single
> leading whitespace character for each name.  I'd like to compare this list
> of names to another list (also in .csv format but in a different file)
> using a simple Python script, but in order to do that I need to strip the
> leading whitespace from all of the names or none of them will match the
> names in the second list.  However, when I try to do this as follows:
> 
> positions = open('/home/guillaume/Documents/playerpos.csv')
> 
> for line in positions:
> info = line.split(',')
> name = info[0]
> name = name.strip()
> print name #to examine the effect of name.strip()
> 
> I keep getting all of the names with the leading whitespace character NOT
> removed (for example: " Jeff Adrien". Why is this happening?

Do you mean

print name.strip()

still prints a leading space? If so, what does 

print repr(name)

print? If it is

"\xc2\xa0Jeff Adrien"

try 

print name.decode("utf-8").strip()

Or do you mean the effect of strip() is not permanent? You have to modify 
the line then:

cleaned_lines = []
for line in positions:
info = line.split(",")
info[0] = info[0].strip()
cleaned_lines.append(",".join(info))
positions = cleaned_lines

 
> The following is a sample of the .csv file (the one I'm trying to remove
> the whitespace from) opened in gedit, the built-in Ubuntu text editor:
> 
>  Jeff Adrien,SF,Houston Rockets
>  Arron Afflalo,SG,Denver Nuggets
>  Maurice Ager,GF,Minnesota Timberwolves
>  Blake Ahearn,PG,Los Angeles Clippers
>  Alexis Ajinca,FC,Toronto Raptors
>  Solomon Alabi,C,Toronto Raptors
>  Cole Aldrich,C,Oklahoma City Thunder
>  LaMarcus Aldridge,FC,Portland Trail Blazers
>  Joe Alexander,SF,New Orleans Hornets
>  Lavoy Allen,FC,Philadelphia 76ers
>  Malik Allen,FC,Orlando Magic
>  Ray Allen,SG,Boston Celtics
>  Tony Allen,GF,Memphis Grizzlies
>  Lance Allred,C,Indiana Pacers
>  Rafer Alston,PG,Miami Heat
> 
> Any help with this seemingly simple but maddening issue would be much
> appreciated.
> 
> thanks,
> Guillaume


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


Problem using s.strip() to remove leading whitespace in .csv file

2012-02-29 Thread Guillaume Chorn
Hello All,

I have a .csv file that I created by copying and pasting a list of all the
players in the NBA with their respective teams and positions (
http://sports.yahoo.com/nba/players?type=lastname&first=1&query=&go=GO!).
Unfortunately, when I do this I have no choice but to include a single
leading whitespace character for each name.  I'd like to compare this list
of names to another list (also in .csv format but in a different file)
using a simple Python script, but in order to do that I need to strip the
leading whitespace from all of the names or none of them will match the
names in the second list.  However, when I try to do this as follows:

positions = open('/home/guillaume/Documents/playerpos.csv')

for line in positions:
info = line.split(',')
name = info[0]
name = name.strip()
print name #to examine the effect of name.strip()

I keep getting all of the names with the leading whitespace character NOT
removed (for example: " Jeff Adrien". Why is this happening?

The following is a sample of the .csv file (the one I'm trying to remove
the whitespace from) opened in gedit, the built-in Ubuntu text editor:

 Jeff Adrien,SF,Houston Rockets
 Arron Afflalo,SG,Denver Nuggets
 Maurice Ager,GF,Minnesota Timberwolves
 Blake Ahearn,PG,Los Angeles Clippers
 Alexis Ajinca,FC,Toronto Raptors
 Solomon Alabi,C,Toronto Raptors
 Cole Aldrich,C,Oklahoma City Thunder
 LaMarcus Aldridge,FC,Portland Trail Blazers
 Joe Alexander,SF,New Orleans Hornets
 Lavoy Allen,FC,Philadelphia 76ers
 Malik Allen,FC,Orlando Magic
 Ray Allen,SG,Boston Celtics
 Tony Allen,GF,Memphis Grizzlies
 Lance Allred,C,Indiana Pacers
 Rafer Alston,PG,Miami Heat

Any help with this seemingly simple but maddening issue would be much
appreciated.

thanks,
Guillaume
-- 
http://mail.python.org/mailman/listinfo/python-list


New Science Discovery: Perl Idiots Remain Idiots After A Decade!New Science Discovery: Perl Idiots Remain Idiots After A Decade!

2012-02-29 Thread Xah Lee
New Science Discovery: Perl Idiots Remain Idiots After A Decade!

A excerpt from the new book 〈Modern Perl〉, just published, chapter 4
on “Operators”. Quote:

«The associativity of an operator governs whether it evaluates from
left to right or right to left. Addition is left associative, such
that 2 + 3 + 4 evaluates 2 + 3 first, then adds 4 to the result.
Exponentiation is right associative, such that 2 ** 3 ** 4 evaluates 3
** 4 first, then raises 2 to the 81st power. »

LOL. Looks like the perl folks haven't changed. Fundamentals of
serious math got botched so badly.

Let me explain the idiocy.

It says “The associativity of an operator governs whether it evaluates
from left to right or right to left.”. Ok, so let's say we have 2
operators: a white triangle △ and a black triangle ▲. Now, by the
perl's teaching above, let's suppose the white triangle is “right
associative” and the black triangle is “left associative”. Now, look
at this:

3 △ 6 ▲ 5

seems like the white and black triangles are going to draw a pistol
and fight for the chick 6 there. LOL.

Now, let me tell you what operator precedence is. First of all, let's
limit ourselfs to discuss operators that are so-called binary
operators, which, in our context, basically means single symbol
operator that takes it's left and right side as operands. Now, each
symbol have a “precedence”, or in other words, the set of operators
has a order. (one easy way to think of this is that, suppose you have
n symbols, then you give each a number, from 1 to n, as their order)
So, when 2 symbols are placed side by side such as 「3 △ 6 ▲ 5」, the
symbol with higher precedence wins. Another easy way to think of this
is that each operator has a stickiness level. The higher its level, it
more sticky it is.

the problem with the perl explanations is that it's one misleading
confusion ball. It isn't about “left/right associativity”. It isn't
about “evaluates from left to right or right to left”. Worse, the word
“associativity” is a math term that describe a property of algebra
that has nothing to do with operator precedence, yet is easily
confused with because it is a property about order of evaluation. (for
example, the addition function is associative, meaning: 「(3+6)+5 =
3+(6+5)」.)

compare it with this:

〈Perl & Python: Complex Numbers〉
http://xahlee.org/perl-python/complex_numbers.html

and for a good understanding of functions and operators, see:

〈What's Function, What's Operator?〉
http://xahlee.org/math/function_and_operators.html
-- 
http://mail.python.org/mailman/listinfo/python-list