Re: Sorting a list of lists

2010-02-12 Thread John Posner
On 2/12/2010 12:45 PM, R (Chandra) Chandrasekhar wrote: Dear Folks, I have lines of values like so: 14, [25, 105, 104] 10, [107, 106, 162] 21, [26, 116, 165] I need to sort them in two ways: (a) By the numeric value of the first column; and (b) by the sum of the elements of the second item i

Re: Modifying Class Object

2010-02-10 Thread John Posner
On 2/10/2010 1:38 PM, Ethan Furman wrote: After all is said and done - if you had a truly good grasp of Python, I might buy your book even if you still had -- ummm -- a less than winning presence on the mailing list; but right now your understanding is not worth paying for. Alf, here's my sug

Re: Creating formatted output using picture strings

2010-02-10 Thread John Posner
On 2/10/2010 2:57 PM, Grant Edwards wrote: On 2010-02-10, pyt...@bdurham.com wrote: [regardning "picture" output format specifiers] I was thinking that there was a built-in function for this common(?) use case I haven't seen that paradigm since my one-and-only exposure to COBOL in a class I

Re: Function attributes

2010-02-10 Thread John Posner
On 2/10/2010 10:24 AM, Bruno Desthuilliers wrote: They didn't break immediately for me -- what am I missing?: The fact that in the OP's snippet, code inside f's body refers to f by its name. Of course! Tx. -John -- http://mail.python.org/mailman/listinfo/python-list

Re: Function attributes

2010-02-10 Thread John Posner
On 2/10/2010 9:36 AM, Steven D'Aprano wrote: On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote: Hi everyone, What is the simplest way to access the attributes of a function from inside it, other than using its explicit name? In a function like f below: def f(*args): f.args = a

Re: Doctests and decorated methods don't get along

2010-02-06 Thread John Posner
On 2/6/2010 6:48 AM, Steven D'Aprano wrote: class MyStaticMethod(object): """Emulate built-in staticmethod descriptor.""" def __init__(self, f): self.f = f def __get__(self, obj, objtype=None): return self.f How about using a function, instead of a class, to imp

Re: which

2010-02-05 Thread John Posner
On 2/5/2010 11:53 AM, Gerald Britton wrote: Also, I'm contractually obligated to admonish you not to "top post". Contract? Joke. (I know it's hard to tell.) At any rate, I proposed the 3-line format specifically because it separates the data values from the if-then-else machinery, mak

Re: which

2010-02-05 Thread John Posner
On 2/5/2010 11:26 AM, Gerald Britton wrote: sure, but it will fit nicely on one line if you like On Fri, Feb 5, 2010 at 11:22 AM, John Posner wrote: On 2/5/2010 11:06 AM, Gerald Britton wrote: [snip] Last August [1], I offered this alternative: self.cmd = (cmd.replace

Re: which

2010-02-05 Thread John Posner
On 2/5/2010 11:06 AM, Gerald Britton wrote: [snip] Last August [1], I offered this alternative: self.cmd = (cmd.replace(r'${ADDR}',ip) if isinstance(cmd, str) else cmd) But it didn't get much love in this forum! I'd probably go for that one as well though I mig

Re: which

2010-02-05 Thread John Posner
On 2/5/2010 9:21 AM, mk wrote: if isinstance(cmd, str): self.cmd = cmd.replace(r'${ADDR}',ip) else: self.cmd = cmd or self.cmd = cmd if isinstance(cmd, str): self.cmd = cmd.replace(r'${ADDR}',ip) (lunatic fringe?) Last August [1], I offered this alternative: self.cmd = (cmd

Re: odd drawing problem with turtle.py

2010-01-31 Thread John Posner
> I'm on Python 2.5, but using the updated turtle.py Version 1.0.1 - 24. 9. 2009. > The following script draws 5 circles, which it is supposed to, but then > doesn't draw the second turtle which is supposed to simply move forward. > Any ideas? Try commenting out this statement: self.turtle.t

Re: Still too slow

2010-01-30 Thread John Posner
On 1/30/2010 6:08 PM, elsa wrote: Hello again, Thanks for the tips r.e random.ranint(). This improved matters somewhat, however my program is still too slow. If anyone has any further tips on how to speed it up, they would be much appreciated! So, I'm calling evolve(L,limit) from the interactiv

Re: For loop searching takes too long!

2010-01-28 Thread John Posner
On 1/28/2010 6:52 PM, elsa wrote: Hi guys, I've got a problem with my program, in that the code just takes too long to run. Here's what I'm doing. If anyone has any tips, they'd be much appreciated! So, say I have a list of lists that looks something like this (I'm using a list of lists, rather

Re: Wrap a function

2010-01-28 Thread John Posner
On 1/28/2010 3:45 PM, Joan Miller wrote: On 28 ene, 20:34, Joan Miller wrote: On 28 ene, 20:20, Peter wrote: On Jan 29, 6:58 am, John Posner wrote: On 1/28/2010 2:24 PM, Joan Miller wrote: On 28 ene, 19:16, Josh Hollandwrote: On 2010-01-28, Joan Millerwrote: I've to

Re: Wrap a function

2010-01-28 Thread John Posner
On 1/28/2010 2:24 PM, Joan Miller wrote: On 28 ene, 19:16, Josh Holland wrote: On 2010-01-28, Joan Miller wrote: I've to call to many functions with the format: run("cmd") Check the docs on os.system(). No. I've a function that uses subprocess to run commands on the same shell and so s

Re: Need help with a program

2010-01-28 Thread John Posner
On 1/28/2010 10:50 AM, evilweasel wrote: I will make my question a little more clearer. I have close to 60,000 lines of the data similar to the one I posted. There are various numbers next to the sequence (this is basically the number of times the sequence has been found in a particular sample).

Re: pylint and the 'missing docstring' warning

2010-01-26 Thread John Posner
On 1/26/2010 9:22 AM, Jean-Michel Pichavant wrote: John Posner wrote: On 1/26/2010 8:43 AM, Jean-Michel Pichavant wrote: Hello, Does anyone using pylint knows a way to make pylint ignore these 'missing docstring' warnings when the base class version of the method actually d

Re: pylint and the 'missing docstring' warning

2010-01-26 Thread John Posner
On 1/26/2010 8:43 AM, Jean-Michel Pichavant wrote: Hello, Does anyone using pylint knows a way to make pylint ignore these 'missing docstring' warnings when the base class version of the method actually defines the docstring ? 'Cause my doc builder (epydoc) handle it properly and propagate docst

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread John Posner
On 1/22/2010 7:17 AM, Gilles Ganault wrote: Hello I use a dictionary to keep a list of users connected to a web site. To avoid users from creating login names that start with digits in order to be listed at the top, I'd like to sort the list differently every minute so that it'll start with the

Re: Dynamic text color

2010-01-08 Thread John Posner
On Fri, 08 Jan 2010 14:28:57 -0500, MRAB wrote: Dave McCormick wrote: On Wed, Jan 6, 2010 at 9:18 AM, John Posner <mailto:jjpos...@optimum.net>> wrote: On Tue, 05 Jan 2010 16:54:44 -0500, Dave McCormick mailto:mackrac...@gmail.com>> wrote: But it is not wh

Re: QDoubleValidator

2010-01-06 Thread John Posner
On Wed, 06 Jan 2010 17:47:37 -0500, Zabin wrote: On Jan 7, 10:23 am, Zabin wrote: Hey! I am new PyQt programmer and want to restrict users to allow only numeric values into a table and lineedit boxes. I found the QDoubleValidator class but am unsure as to how to implement it. (I am a little

Re: Dynamic text color

2010-01-06 Thread John Posner
On Tue, 05 Jan 2010 16:54:44 -0500, Dave McCormick wrote: But it is not what I am wanting. I first thought to make it look for a space but that would not work when a single character like "#" is to be colored if there is a "string" of them. Or if all of the characters between quotes are

Re: Dynamic text color

2010-01-05 Thread John Posner
On Tue, 05 Jan 2010 15:08:04 -0500, Dave McCormick wrote: It's certainly a mistake to use the expression "str(rList).split()". Using str() to convert the list "rList" into a string creates a mess that includes square-bracket characters. Did this actually work for you? It sort of worked

Re: parsing an Excel formula with the re module

2010-01-05 Thread John Posner
On Tue, 05 Jan 2010 13:12:00 -0500, vsoler wrote: Hello, I am acessing an Excel file by means of Win 32 COM technology. For a given cell, I am able to read its formula. I want to make a map of how cells reference one another, how different sheets reference one another, how workbooks reference

Re: Dynamic text color

2010-01-05 Thread John Posner
On Tue, 05 Jan 2010 10:31:09 -0500, Dave McCormick wrote: ... But this is what I have so far. ## file = 'red.txt' file = open("red.txt","r") rList = file.readlines() file.close() redList = str(rList).split() Dave, you're doing exactly the right thing: gradually expanding your

Re: A null program - what is it doing?

2010-01-05 Thread John Posner
No doubt a dumb question from a noob: The following program (a cut down version of some test code) uses no CPU, and does not terminate: import sys from PyQt4.QtCore import * if __name__=="__main__": app = QCoreApplication(sys.argv) sys.exit(app.exec_()) What is the program doing?

Re: Dynamic text color

2010-01-04 Thread John Posner
On Fri, 01 Jan 2010 21:01:04 -0500, Cousin Stanley wrote: I was not familiar with the re.finditer method for searching strings ... Stanley and Dave -- So far, we've just been using finditer() to perform standard-string searches (e.g. on the word "red"). Since Dave now wants to

Re: Dynamic text color

2010-01-02 Thread John Posner
On Sat, Jan 2, 2010 at 1:47 PM, Dave McCormick wrote: WooHoo!!! I got it!!! Yup, I am sure it can be optimized but it works!!! Hmmm ... it doesn't work for me ... RED for word in redList: new_Rword(complete, word) def new_Rword(complete, word): Tbox.tag_remov

Re: Dynamic text color

2010-01-02 Thread John Posner
On Sat, Jan 2, 2010 at 1:47 PM, Dave McCormick wrote: WooHoo!!! I got it!!! Yup, I am sure it can be optimized but it works!!! Dave, please ignore a couple of my bogus complaints in the previous message: ... you call function new_Rword() before you define it ... this version also has

Re: multivariable assignment

2009-12-31 Thread John Posner
On Thu, 31 Dec 2009 11:32:04 -0500, Andreas Waldenburger wrote: On Thu, 31 Dec 2009 08:13:35 -0800 (PST) davidj411 wrote: I am not sure why this behavior is this way. at beginning of script, i want to create a bunch of empty lists and use each one for its own purpose. however, updating one l

Re: Dynamic text color

2009-12-31 Thread John Posner
On Thu, 31 Dec 2009 10:24:44 -0500, Dave McCormick wrote: John, Thank you for the tips. I was changing the line-column index to a FLOAT because the search would return the starting position (pos) of the string, then by making it a FLOAT and adding the string length I was able to get the en

Re: Dynamic text color

2009-12-30 Thread John Posner
On Wed, 30 Dec 2009 12:58:06 -0500, Dave McCormick wrote: Hi All, I am new to Python and the list so I hope I am posting this correctly... I am working on a way to have text automatically formated in a Tkiniter Text widget and would like some input on my code. Currently I am using Python

Re: How to iterate the input over a particular size?

2009-12-29 Thread John Posner
On Tue, 29 Dec 2009 01:35:41 -0500, Steven D'Aprano wrote: On Tue, 29 Dec 2009 00:49:50 -0500, John Posner wrote: On Sun, 27 Dec 2009 09:44:17 -0500, joy99 wrote: Dear Group, I am encountering a small question. Suppose, I write the following code, input_string=raw_input("PRIN

Re: How to iterate the input over a particular size?

2009-12-29 Thread John Posner
On Tue, 29 Dec 2009 01:35:41 -0500, Steven D'Aprano wrote: On Tue, 29 Dec 2009 00:49:50 -0500, John Posner wrote: On Sun, 27 Dec 2009 09:44:17 -0500, joy99 wrote: Dear Group, I am encountering a small question. Suppose, I write the following code, input_string=raw_input("PRIN

Re: How to iterate the input over a particular size?

2009-12-29 Thread John Posner
On Tue, 29 Dec 2009 01:35:41 -0500, Steven D'Aprano wrote: On Tue, 29 Dec 2009 00:49:50 -0500, John Posner wrote: On Sun, 27 Dec 2009 09:44:17 -0500, joy99 wrote: Dear Group, I am encountering a small question. Suppose, I write the following code, input_string=raw_input(&qu

Re: How to iterate the input over a particular size?

2009-12-28 Thread John Posner
On Sun, 27 Dec 2009 09:44:17 -0500, joy99 wrote: Dear Group, I am encountering a small question. Suppose, I write the following code, input_string=raw_input("PRINT A STRING:") string_to_word=input_string.split() len_word_list=len(string_to_word) if len_word_list>9: rest_words=

Re: PyQt Signals and multiple sources

2009-12-20 Thread John Posner
On Sun, 20 Dec 2009 16:59:11 -0500, Zabin wrote: I am beginner in programming in pyqt. I have been trying to call the same function from multiple events- but each event results in a different instance of the function. I am just unable to figure out how to retrieve the source which calls the fun

Re: Class variables static by default?

2009-12-19 Thread John Posner
On Sat, 19 Dec 2009 19:10:13 -0500, KarlRixon wrote: Given the following script, I'd expect p1.items to just contain ["foo"] and p2.items to contain ["bar"] but they both contain ["foo", "bar"]. Why is this? Are object variables not specific to their instance? --- #!/u

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments

2009-12-19 Thread John Posner
On Fri, 18 Dec 2009 13:00:48 -0500, Alf P. Steinbach wrote: Chapter 2 is about Basic Concepts (of programming). It's the usual: variables, ... 1. Overall suggestion You have a tendency to include non-pertinent asides [1]. But then, rambling a bit endows a manuscript with the author's

Re: How to create a self-destructing Tkinter dialog box?

2009-12-17 Thread John Posner
On Thu, 17 Dec 2009 02:09:03 -0500, Martin P. Hellwig wrote: mrstevegross wrote: Ok, I would like to put together a Python/Tkinter dialog box that displays a simple message and self-destructs after N seconds. Is there a simple way to do this? Thanks, --Steve Just, thinking aloud, I proba

Re: Moving from Python 2 to Python 3: A 4 page "cheat sheet"

2009-12-02 Thread John Posner
On Wed, 02 Dec 2009 13:34:11 -0500, Carsten Haese wrote: With string interpolation, you don't need to do that, either. '%*d' % (8,456) ' 456' Thanks, Carsten and Mark D. -- I'd forgotten about the use of "*" in minimum-field-width specs and precision specs (doh). How about this:

Re: Moving from Python 2 to Python 3: A 4 page "cheat sheet"

2009-12-02 Thread John Posner
On Wed, 02 Dec 2009 10:55:23 -0500, Mark Summerfield wrote: On Dec 1, 2:03 pm, Mark Summerfield wrote: I've produced a 4 page document that provides a very concise summary of Python 2<->3 differences plus the most commonly used new Python 3 features. It is aimed at existing Python 2 program

Re: Noobie python shell question

2009-11-30 Thread John Posner
On Sun, 29 Nov 2009 22:03:09 -0500, tuxsun wrote: I've been working in the shell on and off all day, and need to see if a function I defined earlier is defined in the current shell I'm working in. Is there a shell command to get of list of functions I've defined? How about this: #

Re: object indexing and item assignment

2009-11-13 Thread John Posner
King wrote: class MyFloat(object): def __init__(self, value=0.): self.value = value def set(self, value): self.value = value def get(self): return self.value class MyColor(object): def __init__(self, value=(0,0,0)): self.value = (MyFloat(value[0

Re: Program to compute and print 1000th prime number

2009-11-07 Thread John Posner
Robert P. J. Day said: the ubiquitous sieve of eratosthenes requires you to pre-specify your maximum value, after which -- once the sieve completes -- all you know is that you have all of the prime numbers up to n. whether you'll have 1000 of them isn't clear, which means that you might have t

Re: Adding a menu to Tkinter

2009-10-26 Thread John Posner
Ronn Ross wrote: I'm attempting to add a menu bar to my Tkinter app. I can't figure out the correct syntax. Can someone help? I get this error when I run the app: Traceback (most recent call last): File "tkgrid.py", line 26, in app = App(root) File "tkgrid.py", line 10, in __init__

Re: quit button

2009-10-25 Thread John Posner
linda.s wrote: When I click "quit" button, why the following code has problem? from Tkinter import * colors = ['red', 'green', 'yellow', 'orange', 'blue', 'navy'] def gridbox(parent): r = 0 for c in colors: l = Label(parent, text=c, relief=RIDGE, width=25) e = Entry(pa

Re: a splitting headache

2009-10-22 Thread John Posner
[resend, with Subject line corrected and formatting crud deleted] Mensanator wrote: That's interesting. If string.splitfields(delim) was equivalent to str.split(sep), it would have been useful to add the phrase "str.split(sep) is equivalent to the old string.splitfields(delim) which no longer ex

Re:

2009-10-22 Thread John Posner
Mensanator wrote: That's interesting. If string.splitfields(delim) was equivalent to str.split(sep), it would have been useful to add the phrase "str.split(sep) is equivalent to the old string.splitfields(delim) which no longer exists." to the docs. That way, a search on "splitfields" would direc

Re: a splitting headache

2009-10-22 Thread John Posner
Carl Banks wrote: s.split() and s.split(sep) do different things, and there is no string sep that can make s.split(sep) behave like s.split(). That's not unheard of but it does go against our typical expectations. It would have been a better library design if s.split() and s.split(sep) were d

Re: a splitting headache

2009-10-16 Thread John Posner
Mensenator said: c = '001110' c.split('0') ['', '', '1', '', '', '', '11', ''] Ok, the consecutive delimiters appear as empty strings for reasons unknown (except for the first one). Except when they start or end the string in which case the first one is included. Maybe there's a r

Re: UnboundLocalError with extra code after return

2009-09-30 Thread John Posner
Duncan Booth wrote: / class CallableOnlyOnce(object): /def __init__(self, func): self.func = func def __call__(self): f = self.func if f: self.func = None return f() / def callonce(func): / return CallableOnlyOnce(func) / @callonce /

[off-topic] Pessimal (was: Detecting changes to a dict)

2009-09-29 Thread John Posner
If you can enumerate the language of possible inputs you could generate a unique binary representation. Against a language of size l that would only take you O(l*n) to build the repr for a dict and for certain repr sizes the comparison could be O(1), making the entire operation O(l*n+l*m) vs O(n

Re: [Tkinter] messed callbacks

2009-09-09 Thread John Posner
def cb12(): return output(c1+'->'+c2) def cb21(): return output(c2+'->'+c1) I think these can be simplified, e.g: def cb12(): output(c1+'->'+c2) But I'd go with the functools.partial approach. You can save some code by making output() do more of the work: #---

Re: Need help with Python scoping rules

2009-08-25 Thread John Posner
Stephen Hansen said: But http://docs.python.org/tutorial/classes.html says, in Section 9.3 "A First Look at Classes": When a class definition is entered, a new namespace is created, and used as the local scope — thus, all assignments to local variables go into this new name

Re: Need help with Python scoping rules

2009-08-25 Thread John Posner
7stud said: python ignores the names inside a function when it creates the function. This "program" will not produce an error: def f(): print x python parses the file and creates the function object and assigns the function object to the variable f. It's not until you execute the functio

Re: Need help with Python scoping rules

2009-08-25 Thread John Posner
Diez said: Classes are not scopes. So the above doesn't work because name resolution inside functions/methods looks for local variables first, then for the *global* scope. There is no class-scope-lookup. But http://docs.python.org/tutorial/classes.html says, in Section 9.3 "A First Look at

Re: conditional for-statement

2009-08-23 Thread John Posner
Hi, i was wondering if there is a syntax alike: for i in range(10) if i > 5: print i You can write for i in filter(lambda i: i > 5, range(10)): print i but for i in range(10): if i > 5: print i it' better readable, and for i in range(6,10): print i it's e

Re: Code formatting question: conditional expression

2009-08-19 Thread John Posner
Diez wrote: No. I love them. But not if they are so large that they stretch over several lines (or to many columns). foo = bar if cond else baz is more than fine for me. But foo = I_need_to_do_something_really_complicated_here() if cond else baz isn't, because one doesn't grasp as easily in

Re: Code formatting question: conditional expression

2009-08-18 Thread John Posner
I wonder if it is appropriate to replace the None sentinel with one that is an instance of Block() e.g. size = total - P.BASE excessblk = Block(size, srccol, carry_button_suppress=True, empty_block=(size <= 0) ) In this particular case, Richard, I don't think so. The Block class is an a

Re: Code formatting question: conditional expression

2009-08-18 Thread John Posner
My choice would be excessblk = None if total > P.BASE: excessblk = ... Diez and Jean-Michel, Ha! Your suggestion above was my *original* coding. It looks like I'm evolving backwards! But doesn't it violate the DRY principle? The token "excessblk" appears twice instead of once. Than

Code formatting question: conditional expression

2009-08-18 Thread John Posner
While refactoring some code, I ran across an opportunity to use a conditional expression. Original: if total > P.BASE: excessblk = Block(total - P.BASE, srccol, carry_button_suppress=True) else: excessblk = None Is there any consensus on how to format a conditional expression that i

Re: XML parsing with python

2009-08-17 Thread John Posner
Use the iterparse() function of the xml.etree.ElementTree package. http://effbot.org/zone/element-iterparse.htm http://codespeak.net/lxml/parsing.html#iterparse-and-iterwalk Stefan iterparse() is too big a hammer for this purpose, IMO. How about this: from xml.etree.ElementTree import E

Re: Announcing PythonTurtle

2009-08-05 Thread John Posner
OK, then why the statements "from turtle import *" in the modules turtleprocess.py and turtlewidget.py? Yes, I see that now (he said meekly, too sheepish to complain about being misled by an unfortunate naming choice). Tx, John -- http://mail.python.org/mailman/listinfo/python-list

Re: Announcing PythonTurtle

2009-08-04 Thread John Posner
Certainly John- although I have not embedded the turtle module at all, I just wrote my own. OK, then why the statements "from turtle import *" in the modules turtleprocess.py and turtlewidget.py? Tx, John -- http://mail.python.org/mailman/listinfo/python-list

Re: Announcing PythonTurtle

2009-08-03 Thread John Posner
... I would also venture to say a key-map of sorts that is available thru the help menu where one could push an "Up" button, or a "rotate" button, and have the proper command inserted in the prompt, and then have the command execute, may also help make the connections here, a sort of *real* Visu

Re: Tkinter / Entry widget problem

2009-07-14 Thread John Posner
Andras Szabo wrote: Hello. I searched the archives but couldn't find a solution to a problem related to the Entry widget in Tkinter. When creating a pop-up window in an app, which contains an Entry widget, I want this widget to contain some default string, to have all this default string s

Re: Tkinter only: table widget with canvas...

2009-07-11 Thread John Posner
There's a working app at http://cl1p.net/tkinter_table_headers/ Thank you for this example. However, one issue to that... When resizing the window (vertical) then the header moves away from the table. How can I avoid this with the grid? With "pack" I now this... Oops ... packing can be tricky

Re: Tkinter only: table widget with canvas...

2009-07-10 Thread John Posner
Hi -- a) Assume I would have some different widgets to add per row. How do I get the maximum row height? If you are placing widgets in a table like this: w.grid(row=a, column=b) ... where the *master* of widget "w" is a Tkinter.Frame named "table_frm", then you can determine the height

Re: tkinter and widget placement after resizing

2009-05-08 Thread John Posner
jamieson wrote: i.e. start out with a window like this: [1][4][7] [2][5][8] [3][6][9] make the main window larger and end up with this: [1][6] [2][7] [3][8] [4][9] [5 Here's a solution, using Label widgets for clarity. The keys are: * start numbering from zero, not one * use divmod() on an

Re: Re: list comprehension question

2009-05-01 Thread John Posner
Shane Geiger wrote: if type(el) == list or type(el) is tuple: A tiny improvement: if type(el) in (list, tuple): -- http://mail.python.org/mailman/listinfo/python-list

Re: Re: Please explain this strange Python behaviour

2009-04-30 Thread John Posner
Stephen Hansen wrote: I have a feeling this might start one of those uber-massive "pass by value / reference / name / object / AIEE" threads where everyone goes around in massive circles explaining how Python uses one or another parameter passing paradigm and why everyone else is wrong... but..

Re: Please explain this strange Python behaviour

2009-04-30 Thread John Posner
Duncan Booth wrote: Tim Chase wrote: There _are_ cases where it's a useful behavior, but they're rare, so I don't advocate getting rid of it. But it is enough of a beginner gotcha that it really should be in the Python FAQ at www.python.org/doc/faq/general/ That's an excellent idea! So

Re: Re: sorted() erraticly fails to sort string numbers

2009-04-28 Thread John Posner
uuid wrote: I am at the same time impressed with the concise answer and disheartened by my inability to see this myself. My heartfelt thanks! Don't be disheartened! Many people -- myself included, absolutely! -- occasionally let a blind spot show in their messages to this list. BTW: contai

Re: and [True,True] --> [True, True]?????

2009-04-26 Thread John Posner
Arnaud Delobelle wrote: return any( not val for val in value_list ) This is the same as: return not all(value_list) Yes, I should have remembered De Morgan's Theorem. Thanks! -John -- http://mail.python.org/mailman/listinfo/python-list

Re: and [True,True] --> [True, True]?????

2009-04-26 Thread John Posner
jazbees wrote: > I'm surprised to see that the use of min and max for element-wise > comparison with lists has not been mentioned. When fed lists of True/ > False values, max will return True if there is at least one True in > the list, while min will return False if there is at least one False.

Re: color propagation in tkinter

2009-04-22 Thread John Posner
Alan G Isaac wrote: Yes, that's what I am currently doing. But it seems that that is exactly the kind of thing we are enabled to avoid with e.g., named fonts. So I was hoping for an equivalent functionality for colors. From your answer, I am guessing there is none. Not sure this would help, but

Re: any(), all() and empty iterable

2009-04-16 Thread John Posner
Tim Chase wrote: I will probably leave the lead-in sentence as-is but may add another sentence specifically covering the case for an empty iterable. as one of the instigators in this thread, I'm +1 on this solution. Thanks for weighing in, Raymond. As long as people are getting in their last

Re: Re: How to check all elements of a list are same or different

2009-04-15 Thread John Posner
Scott David Daniels wrote: Assuming you really are going for "is" comparison, how about: max(id(x) for x in mylist) == min(id(x) for x in mylist) It has the advantage that if [id(x) for x in mylist] = [2N, 1N, 3N], you get the answer you desire. Oops -- got me! -John -- http://mail.python

Re: Re: How to check all elements of a list are same or different

2009-04-15 Thread John Posner
Chris Rebert wrote: Ah, okay. Then you want: def all_same(lst): return len(set(lst)) == 1 def all_different(lst): return len(set(lst)) == len(lst) Note that these require all the elements of the list to be hashable. This solution relies on the object ID -- no hashability required:

Re: any(), all() and empty iterable

2009-04-14 Thread John Posner
Tim Chase wrote: I still prefer "Return False if any element of the iterable is not true" or "Return False if any element in the iterable is false" because that describes exactly what the algorithm does. Granted, anybody with a mote of Python skills can tell that from the algorithm, but if you

Re: Re: Re: Generators/iterators, Pythonicity, and primes

2009-04-12 Thread John Posner
Duncan Booth wrote: John Posner wrote: Do know what in the itertools implementation causes adding a 'if p <= sqrt(n)' clause to *decrease* performance, while adding a 'takewhile()' clause *increases* performance? I haven't timed it, but I would guess t

Re: Re: Generators/iterators, Pythonicity, and primes

2009-04-11 Thread John Posner
Arnaud Delobelle wrote: You could do something like this with the help of itertools.ifilter: prime_gen = ifilter( lambda n, P=[]: all(n%p for p in P) and not P.append(n), count(2) ) Formidable! (both the English and French meanings) This is the most elegant, Sieve of Eratos

Re: Re: Re: Why does Python show the whole array?

2009-04-09 Thread John Posner
> Peter Otten wrote: >> Could you explain why you prefer 'contains(belly, beer)' >> or 'belly.contains(beer)' over 'beer in belly'? The last form may be a bit >> harder to find in the documentation, but once a newbie has learned about >> it he'll find it easy to remember. andrew cooke wrote:

Re: Re: Why does Python show the whole array?

2009-04-09 Thread John Posner
Hrvoje Niksic wrote: > if test.contains(item) # would return a Boolean value > >> That's a string method, not a function in the string module. Oops, of course. import operator operator.contains('foo', 'o') That's pretty good, and IMHO a bit better than John Machin's suggestion

Re: Re: Why does Python show the whole array?

2009-04-09 Thread John Posner
Lawrence D'Oliveiro wrote: > Fine if it only happened once. But it's a commonly-made mistake. At some > point you have to conclude that not all those people are stupid, there > really is something wrong with the design. I think "something wrong with the design" is overstating the case a bit, an

Re: Re: How can I change size of GUI?

2009-04-07 Thread John Posner
For what definition of 'did not work'? Seems perfectly fine to me. Just try to add the lines: root = Tk() Try adding a line like this: root.geometry("400x300+100+75") ... which means: "make the window 400 pixels wide and 300 pixels high, with the upperleft corner at point (100,75)"

Re: Weird Tk Canvas coordinate issue

2009-04-06 Thread John Posner
Tim Shannon wrote: I'm new to python, so keep that in mind. I have a tk Canvas that I'm trying to draw on, and I want to start my drawing at an offset (from 0) location. So I can tweak this as I code, I set this offset as a class level variable: def ClassName: OFFSET = 20 def __i

Re: Generators/iterators, Pythonicity, and primes

2009-04-05 Thread John Posner
>> > g = (lambda primes = []: >> > (n for n in count(2) if >> > (lambda x, primes: >> > (primes.append(x) or True >> > if all(x%p for p in primes if p <= sqrt(x)) >> > else False) >> > )(n, primes) >> >

Re: Generators/iterators, Pythonicity, and primes

2009-04-05 Thread John Posner
Kay Schluehr wrote: > That's because it is *one* expression. The avoidance of named > functions makes it look obfuscated or prodigious. Once it is properly > dissected it doesn't look that amazing anymore. > > Start with: > > (n for n in count(2) if is_prime(n, primes)) > > The is_prime function

Re: Generators/iterators, Pythonicity, and primes

2009-04-05 Thread John Posner
Kay Schluehr said: > g = (lambda primes = []: > (n for n in count(2) \ > if > (lambda n, primes: (n in primes if primes and n<=primes[-1] \ > else > (primes.append(n) or True \ > if all(n%p for p in primes if p <= sqrt(n)) \ >

RE: possible pairings in a set

2009-04-04 Thread John Posner
>> Also, if my code is considered ugly or redundant by this community, >> can you make suggestions to clean it up? Python is pretty mature: if you have a simple, generic problem, the chances are that someone else has already solved it, packaging the solution in a library (or "module"). For your

RE: Generators/iterators, Pythonicity, and primes

2009-04-04 Thread John Posner
Mark Tolonen said: >> p <= sqrt(n) works a little better :^) >> >> -Mark >> Right you are -- I found that bug in my last-minute check, and then I forgot to trannscribe the fix into the email message. Duh -- thanks! -John E-mail message checked by Spyware Doctor (6.0.0.386) Database

Generators/iterators, Pythonicity, and primes

2009-04-04 Thread John Posner
Inspired by recent threads (and recalling my first message to Python edu-sig), I did some Internet searching on producing prime numbers using Python generators. Most algorithms I found don't go for the infinite, contenting themselves with "list all the primes below a given number". Here's a very P

RE: Which is more Pythonic? (was: Detecting Binary content in files)

2009-04-01 Thread John Posner
>> >    mrkrs_alt2 = filter(lambda b: b > 127 or b in list("\r\n\t"), block) >> > >> >> Never tested my 'pythonicity', but I would do: >> >> def test(b) : b > 127 or b in r"\r\n\t" Oops! Clearly, b in "\r\n\t" is preferable to ... b in list("\r\n\t") You do *not* want to u

Which is more Pythonic? (was: Detecting Binary content in files)

2009-04-01 Thread John Posner
Dennis Lee Bieber presented a code snippet with two consecutive statements that made me think, "I'd code this differently". So just for fun ... is Dennis's original statement or my "_alt" statement more idiomatically Pythonic? Are there even more Pythonic alternative codings? mrkrs = [b for b i

RE: Cannot register to submit a bug report

2009-03-31 Thread John Posner
Terry Ready said: >> > My ISP (AT&T/Yahoo) was blocking email from the Python bug-tracker: "The >> > sending system has been identified as a source of spam". >> >> I hope you were able to suggest to them that that >> identification must be >> an error. Frustrating given the spam sources

RE: Style question - defining immutable class data members

2009-03-31 Thread John Posner
I said: >> > My intent was to fix an obvious omission: a special case >> was discussed in >> > the "Augmented assignment statements" section, but an >> almost-identical >> > special case was omitted from the "Assignment statements" section. After finally getting registered at bugs.python.o

RE: Cannot register to submit a bug report

2009-03-31 Thread John Posner
>> >> We can try to debug this :) >> >> >> >> > E-mail message checked by Spyware Doctor (6.0.0.386) >> >> > Database version: >> >> 5.12060http://www.pctools.com/en/spyware-doctor-antivirus/ >> >> >> >> Any chance it's Spyware Doctor or some anti-virus flagging >> >> the messag

RE: tkinter questions: behavior of StringVar, etc

2009-03-30 Thread John Posner
Eric Brunel said: >> The Tk instance is registered in a hidden variable in the >> Tkinter module. When >> you don't specify a master, it'll use the latest created Tk >> instance one by >> default. BTW, the latest should be the only one: it is >> quite unsafe to create >> several Tk insta

<    1   2   3   >