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-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: 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: 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: 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
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: [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: feature request: string.contains('...')

2010-09-24 Thread John Posner
On 9/24/2010 4:21 AM, Peter Otten wrote: If you are not interested in the position of the substr use the "in" operator: if substr in s: print "found" else: print "not found" Another "missing feature" candidate: sublist >>> 'bc' in 'abcde' True >>> list('bc') in list('abc

Re: feature request: string.contains('...')

2010-09-24 Thread John Posner
On 9/24/2010 2:45 PM, Tim Chase wrote: On 09/24/10 13:01, Ethan Furman wrote: John Posner wrote: Another "missing feature" candidate: sublist >>> 'bc' in 'abcde' True >>> list('bc') in list('abcde') False I'm not aw

Re: Class-level variables - a scoping issue

2010-10-10 Thread John Posner
eal(3) meal.Report()# "This meal includes 3 eggs." meal = SpamMeal() meal.EGGS = 4 meal.Report() # "This meal includes 4 eggs." # -John Posner -- http://mail.python.org/mailman/listinfo/python-list

Re: Class-level variables - a scoping issue

2010-10-11 Thread John Posner
On 10/10/2010 7:02 PM, Steven D'Aprano wrote: On Sun, 10 Oct 2010 18:14:33 -0400, John Posner wrote: Class attributes are often used as "class constants", so how about naming them with UPPERCASE names, like other constants? When you choose to override one of these const

Re: processing input from multiple files

2010-10-14 Thread John Posner
On 10/14/2010 6:08 AM, Christopher Steele wrote: Hi I've been trying to decode a series of observations from multiple files (each file is a different time) and put each type of observation into their own separate file. The script runs successfully for one file but whenever I try it for more they

Re: processing input from multiple files

2010-10-14 Thread John Posner
On 10/14/2010 10:44 AM, Christopher Steele wrote: The issue is that I need to be able to both, split the names of the files so that I can extract the relevant times, and open each individual file and process each line individually. Once I have achieved this I need to append the sorted files ont

Re: processing input from multiple files

2010-10-15 Thread John Posner
On 10/15/2010 6:59 AM, Christopher Steele wrote: Thanks, The issue with the times is now sorted, however I'm running into a problem towards the end of the script: File "sortoutsynop2.py", line 131, in newline = message_type+c+str(station_id)+c+newtime+c+lat+c+lon+c+c+"-"+c+ "002"

Re: overriding a property

2010-10-19 Thread John Posner
On 10/19/2010 9:39 AM, Lucasm wrote: Hi, A question. Is it possible to dynamically override a property? class A(object): @property def return_five(self): return 5 I would like to override the property for an instance of A to say the string 'bla'. Is this the sort of thing

Re: overriding a property

2010-10-20 Thread John Posner
On 10/20/2010 9:59 AM, Lucasm wrote: Thanks for the answers. I would like to override the property though without making special modifications in the main class beforehand. Is this possible? Take a look at http://docs.python.org/reference/datamodel.html#descriptors The last paragraph of Sec

Re: Pythonic way of saying 'at least one of a, b, or c is in some_list'

2010-10-28 Thread John Posner
On 10/28/2010 12:16 PM, [email protected] wrote: It's clear but tedious to write: if 'monday" in days_off or "tuesday" in days_off: doSomething I currently am tending to write: if any([d for d in ['monday', 'tuesday'] if d in days_off]): doSomething Is there a better pythonic

Re: Why "flat is better than nested"?

2010-11-09 Thread John Posner
On 11/9/2010 3:44 PM, Gregory Ewing wrote: I don’t get it. I get it. Does that mean that I don't get it? Yes. As Dr. Feynman said about quantum mechanics. -John -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionary of lists strange behaviour

2010-11-09 Thread John Posner
On 11/9/2010 1:43 PM, Terry Reedy wrote: ... List *is* useful as an initializer for collecitons.defaultdicts. And it was useful when several members of this forum helped me to develop a prime-number generator. See http://www.mail-archive.com/[email protected]/msg288128.html. (I meant t

Question on Django and Django Book

2010-11-13 Thread John Posner
I've started working, as a tech writer, for a Spanish software configuration management company. And I'm investigating the idea of releasing a user manual in the form of a wiki that supports paragraph-by-paragraph commenting. I looked at Django Book [1][2], but it's not clear to me how much of

<    1   2   3