Re: If/then style question

2010-12-17 Thread Kev Dwyer
On Thu, 16 Dec 2010 21:49:07 +, John Gordon wrote: (This is mostly a style question, and perhaps one that has already been discussed elsewhere. If so, a pointer to that discussion will be appreciated!) When I started learning Python, I wrote a lot of methods that looked like

Re: If/then style question

2010-12-17 Thread Steven D'Aprano
On Fri, 17 Dec 2010 10:53:45 -0500, Steve Holden wrote about for...else: This construct appears to be unpopular in actual use, and when it comes up in classes and seminars there is always interesting debate as people discuss potential uses and realise there are useful applications. Yes, I

Re: If/then style question

2010-12-17 Thread Steven D'Aprano
On Fri, 17 Dec 2010 17:26:08 +, Grant Edwards wrote: Give me code that's easy-to-read and doesn't work rather code that works and can't be read any day. Well, in that case, you'll love my new operating system, written in 100% pure Python: [start code] print(this is an operating system)

If/then style question

2010-12-16 Thread John Gordon
(This is mostly a style question, and perhaps one that has already been discussed elsewhere. If so, a pointer to that discussion will be appreciated!) When I started learning Python, I wrote a lot of methods that looked like this: def myMethod(self, arg1, arg2): if some_good_condition

Re: If/then style question

2010-12-16 Thread Ethan Furman
John Gordon wrote: (This is mostly a style question, and perhaps one that has already been discussed elsewhere. If so, a pointer to that discussion will be appreciated!) When I started learning Python, I wrote a lot of methods that looked like this: def myMethod(self, arg1, arg2

Re: If/then style question

2010-12-16 Thread Tim Harig
On 2010-12-16, John Gordon gor...@panix.com wrote: I like this style more, mostly because it eliminates a lot of indentation. However I recall one of my college CS courses stating that one entry, one exit was a good way to write code, and this style has lots of exits. So, take the good

Re: If/then style question

2010-12-16 Thread Grant Edwards
On 2010-12-16, John Gordon gor...@panix.com wrote: (This is mostly a style question, and perhaps one that has already been discussed elsewhere. If so, a pointer to that discussion will be appreciated!) When I started learning Python, I wrote a lot of methods that looked like this: def

Re: If/then style question

2010-12-16 Thread Stefan Sonnenberg-Carstens
Am 16.12.2010 22:49, schrieb John Gordon: (This is mostly a style question, and perhaps one that has already been discussed elsewhere. If so, a pointer to that discussion will be appreciated!) When I started learning Python, I wrote a lot of methods that looked like this: def myMethod

Re: If/then style question

2010-12-16 Thread Ryan Kelly
On Thu, 2010-12-16 at 21:49 +, John Gordon wrote: (This is mostly a style question, and perhaps one that has already been discussed elsewhere. If so, a pointer to that discussion will be appreciated!) When I started learning Python, I wrote a lot of methods that looked like

Re: If/then style question

2010-12-16 Thread Ian Kelly
On Thu, Dec 16, 2010 at 3:41 PM, Stefan Sonnenberg-Carstens stefan.sonnenb...@pythonmeister.com wrote: return [x for x,y in ((bad1,some_bad_condition),(bad2,some_other_bad_condition),(bad3,yet_another_bad_condition),(good1,do_some_useful_stuff() or True)) if x][0] This doesn't work.

Re: If/then style question

2010-12-16 Thread Steven D'Aprano
On Thu, 16 Dec 2010 21:49:07 +, John Gordon wrote: (This is mostly a style question, and perhaps one that has already been discussed elsewhere. If so, a pointer to that discussion will be appreciated!) When I started learning Python, I wrote a lot of methods that looked like

Re: If/then style question

2010-12-16 Thread alex23
John Gordon gor...@panix.com wrote: But lately I've been preferring this style:   def myMethod(self, arg1, arg2):     if some_bad_condition:       return bad1     elif some_other_bad_condition:       return bad2     elif yet_another_bad_condition:       return bad3    

Re: If/then style question

2010-12-16 Thread Joel Koltner
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote in message news:4d0aa5e7$0$29997$c3e8da3$54964...@news.astraweb.com... It doesn't look like you were learning Python. It looks like you were learning C with Python syntax :( True, although in many cases one has to interface to legacy C

Re: If/then style question

2010-12-16 Thread Carl Banks
On Dec 16, 2:56 pm, Ryan Kelly r...@rfk.id.au wrote: On Thu, 2010-12-16 at 21:49 +, John Gordon wrote: (This is mostly a style question, and perhaps one that has already been discussed elsewhere.  If so, a pointer to that discussion will be appreciated!) When I started learning

Re: If/then style question

2010-12-16 Thread Steve Holden
On 12/16/2010 11:32 PM, Carl Banks wrote: On Dec 16, 2:56 pm, Ryan Kelly r...@rfk.id.au wrote: On Thu, 2010-12-16 at 21:49 +, John Gordon wrote: (This is mostly a style question, and perhaps one that has already been discussed elsewhere. If so, a pointer to that discussion

Style question for conditional execution

2010-11-24 Thread Gerald Britton
Writing in Python gives me the luxury of choosing different paradigms for similar operations. Lately I've been thinking about a minor detail that peaked my interest and am curious what others think: Say that I have some function f that I will execute if some variable v evaluates true. Using a

Re: Style question for conditional execution

2010-11-24 Thread Ian
On Nov 24, 11:46 am, Gerald Britton gerald.brit...@gmail.com wrote: Say that I have some function f that I will execute if some variable v evaluates true.  Using a classical procedural approach, I might write:     if v:         f() I might, however, think more in a functional-programming

Re: Style question for conditional execution

2010-11-24 Thread Ed Leafe
On Nov 24, 2010, at 1:46 PM, Gerald Britton wrote: Say that I have some function f that I will execute if some variable v evaluates true. Using a classical procedural approach, I might write: if v: f() I might, however, think more in a functional-programming direction. Then

Re: Style question for conditional execution

2010-11-24 Thread Steven Howe
Both paradigms are in the bash shell. Using a test switch (like -x for executiable) mixed with an or ||. Example: [-x /usr/bin/firefox ] || exit I think it's very clear, to old hands, but not so much for a new or intermediate users. It certainly is the 'cleaner' form. Like the C style

Re: Style question for conditional execution

2010-11-24 Thread Arnaud Delobelle
Gerald Britton gerald.brit...@gmail.com writes: Writing in Python gives me the luxury of choosing different paradigms for similar operations. Lately I've been thinking about a minor detail that peaked my interest and am curious what others think: Say that I have some function f that I will

Re: Style question for conditional execution

2010-11-24 Thread Paul Rubin
Gerald Britton gerald.brit...@gmail.com writes: if v: f() I might, however, think more in a functional-programming direction. Then I might write: v and f() Python has conditional expressions. The above would be: f() if v else None using and is bug-prone. --

Re: Style question for conditional execution

2010-11-24 Thread Asun Friere
On Nov 25, 7:43 am, Paul Rubin no.em...@nospam.invalid wrote: Gerald Britton gerald.brit...@gmail.com writes:     if v:         f() I might, however, think more in a functional-programming direction. Then I might write:     v and f() Python has conditional expressions.  The above

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.org (as described

Re: Style question - defining immutable class data members

2009-03-27 Thread Steve Holden
John Posner wrote: [snip] If the object is a class instance and the attribute reference occurs on both sides of the assignment operator; for example:: self.x = self.x + 1 ... in the RHS expression, ``self.x`` is evaluated with ``getattr()``,

RE: Style question - defining immutable class data members

2009-03-26 Thread John Posner
[snip] If the object is a class instance and the attribute reference occurs on both sides of the assignment operator; for example:: self.x = self.x + 1 ... in the RHS expression, ``self.x`` is evaluated with ``getattr()``, which can access either an

Re: Style question - defining immutable class data members

2009-03-25 Thread John Posner
On Mon Mar 16 03:42:42, I said: RTFM, in section Augmented assignment statements of python301.chm: --- For targets which are attribute references, the initial value is retrieved with a getattr() and the result is assigned with a setattr(). Notice that the two methods do not necessarily

Re: Style question - defining immutable class data members

2009-03-25 Thread Steve Holden
John Posner wrote: On Mon Mar 16 03:42:42, I said: RTFM, in section Augmented assignment statements of python301.chm: --- For targets which are attribute references, the initial value is retrieved with a getattr() and the result is assigned with a setattr(). Notice that the two

Re: Style question - defining immutable class data members

2009-03-24 Thread Aahz
In article mailman.1847.1237048379.11746.python-l...@python.org, Maxim Khitrov mkhit...@gmail.com wrote: Very simple question on the preferred coding style. I frequently write classes that have some data members initialized to immutable values. For example: class Test(object): def

Re: Style question - defining immutable class data members

2009-03-16 Thread Gary Herron
John Posner wrote: Matthew Woodcraft said: I doubt it's because anyone particularly wanted this behaviour; it just falls out of the way '+=' is defined. At the point where 'inst.x += 1' is compiled, Python doesn't know whether 'inst.x' is going to turn out to be a class attribute or an

Re: Style question - defining immutable class data members

2009-03-16 Thread Aaron Brady
On Mar 15, 9:54 pm, Rhodri James rho...@wildebst.demon.co.uk wrote: On Sun, 15 Mar 2009 23:26:04 -, Aaron Brady castiro...@gmail.com   wrote: On Mar 15, 1:50 pm, Rhodri James rho...@wildebst.demon.co.uk wrote: On Sun, 15 Mar 2009 17:55:25 -, Aaron Brady castiro...@gmail.com  

Re: Style question - defining immutable class data members

2009-03-16 Thread Rhodri James
On Mon, 16 Mar 2009 09:31:59 -, Aaron Brady castiro...@gmail.com wrote: [snippety snip] Otherwise, either /1, every instance has its own entries for class functions, and subsequent changes to the class don't affect existing instances, or /2, every method call is of the form x.__class__.foo

Re: Style question - defining immutable class data members

2009-03-15 Thread Matthew Woodcraft
Gary Herron gher...@islandtraining.com writes: Gary Herron gher...@islandtraining.com wrote: No, you are still misinterpreting your results. But you can be forgiven because this is quite a subtle point about Python's attribute access. Here's how it works: On access, self.count (or

Re: Style question - defining immutable class data members

2009-03-15 Thread Rhodri James
On Sun, 15 Mar 2009 13:26:17 -, Matthew Woodcraft matt...@woodcraft.me.uk wrote: [snip Gary Herron's explanation of instance attribute lookup falling back to class attribute lookup] It seems clear to me that Maxim understood all this when he asked his original question (you need to

Re: Style question - defining immutable class data members

2009-03-15 Thread Matthew Woodcraft
Rhodri James rho...@wildebst.demon.co.uk writes: On Sun, 15 Mar 2009 13:26:17 -, Matthew Woodcraft It seems clear to me that Maxim understood all this when he asked his original question (you need to understand this subtlety to know why the trick he was asking about only works for

Re: Style question - defining immutable class data members

2009-03-15 Thread Rhodri James
On Sun, 15 Mar 2009 15:05:04 -, Matthew Woodcraft matt...@woodcraft.me.uk wrote: Rhodri James rho...@wildebst.demon.co.uk writes: On Sun, 15 Mar 2009 13:26:17 -, Matthew Woodcraft It seems clear to me that Maxim understood all this when he asked his original question (you need to

Re: Style question - defining immutable class data members

2009-03-15 Thread Bruno Desthuilliers
Maxim Khitrov a écrit : On Sat, Mar 14, 2009 at 2:07 PM, Gary Herron gher...@islandtraining.com wrote: Maxim Khitrov wrote: Very simple question on the preferred coding style. I frequently write classes that have some data members initialized to immutable values. For example: class

Re: Style question - defining immutable class data members

2009-03-15 Thread Aaron Brady
On Mar 15, 8:56 am, Rhodri James rho...@wildebst.demon.co.uk wrote: On Sun, 15 Mar 2009 13:26:17 -, Matthew Woodcraft   matt...@woodcraft.me.uk wrote: [snip Gary Herron's explanation of instance attribute lookup falling back to class attribute lookup] It seems clear to me that Maxim

Re: Style question - defining immutable class data members

2009-03-15 Thread M R A Barnett
Aaron Brady wrote: [snip] However, in my (opined) interpretation, 'list.append(...) is an in- place operation' is a factual error. In-place operations -also- rebind their 'argument' (FLOBW for lack of better words). 'append' is a by-side-effect operation. However colloquially it's mostly

Re: Style question - defining immutable class data members

2009-03-15 Thread John Posner
(My apologies if the thread has already covered this.) I believe I understand the WHAT in this situation, but I don't understand the WHY ... Given this class definition: class Cls(object): x = 345 ... I observe the following, using IDLE 2.6.1: inst = Cls() Cls.x is inst.x True

Re: Style question - defining immutable class data members

2009-03-15 Thread Aaron Brady
On Mar 15, 12:39 pm, John Posner jjpos...@snet.net wrote: (My apologies if the thread has already covered this.) I believe I understand the WHAT in this situation, but I don't understand the WHY ... Given this class definition:   class Cls(object):       x = 345 ... I observe the

Re: Style question - defining immutable class data members

2009-03-15 Thread Rhodri James
On Sun, 15 Mar 2009 17:55:25 -, Aaron Brady castiro...@gmail.com wrote: On Mar 15, 12:39 pm, John Posner jjpos...@snet.net wrote: (My apologies if the thread has already covered this.) I believe I understand the WHAT in this situation, but I don't understand the WHY ... [snip] My

Re: Style question - defining immutable class data members

2009-03-15 Thread Matthew Woodcraft
John Posner jjpos...@snet.net writes: My question is ... WHY does the interpreter silently create the instance attribute at this point, causing a surprising decoupling from the class attribute? WHY doesn't the interpreter behave as it would with a simple, non-instance variable: python

Re: Style question - defining immutable class data members

2009-03-15 Thread Bruno Desthuilliers
Rhodri James a écrit : On Sun, 15 Mar 2009 17:55:25 -, Aaron Brady castiro...@gmail.com wrote: On Mar 15, 12:39 pm, John Posner jjpos...@snet.net wrote: (snip) Is there a beneficial effect of silently creating the instance attribute, which outweighs the detrimental effects: (1)

Re: Style question - defining immutable class data members

2009-03-15 Thread Matthew Woodcraft
Rhodri James rho...@wildebst.demon.co.uk writes: But do you, though? The only occasion I can think of that I'd want the search to go past the instance is this auto-initialisation, and frankly I'd rather do that in an __init__ anyway. Perhaps static methods or class methods work that way, I

Re: Style question - defining immutable class data members

2009-03-15 Thread Bruno Desthuilliers
John Posner a écrit : (My apologies if the thread has already covered this.) I believe I understand the WHAT in this situation, but I don't understand the WHY ... Given this class definition: class Cls(object): x = 345 ... I observe the following, using IDLE 2.6.1: inst = Cls() Cls.x is

Re: Style question - defining immutable class data members

2009-03-15 Thread R. David Murray
M R A Barnett p...@mrabarnett.plus.com wrote: Aaron Brady wrote: [snip] However, in my (opined) interpretation, 'list.append(...) is an in- place operation' is a factual error. In-place operations -also- rebind their 'argument' (FLOBW for lack of better words). 'append' is a

Re: Style question - defining immutable class data members

2009-03-15 Thread John Posner
Matthew Woodcraft said: I doubt it's because anyone particularly wanted this behaviour; it just falls out of the way '+=' is defined. At the point where 'inst.x += 1' is compiled, Python doesn't know whether 'inst.x' is going to turn out to be a class attribute or an instance attribute

Re: Style question - defining immutable class data members

2009-03-15 Thread Aaron Brady
On Mar 15, 1:50 pm, Rhodri James rho...@wildebst.demon.co.uk wrote: On Sun, 15 Mar 2009 17:55:25 -, Aaron Brady castiro...@gmail.com   wrote: On Mar 15, 12:39 pm, John Posner jjpos...@snet.net wrote: (My apologies if the thread has already covered this.) I believe I   understand the

Re: Style question - defining immutable class data members

2009-03-15 Thread R. David Murray
John Posner jjpos...@snet.net wrote: Summary: I no longer suspect that Python is broken. I *do* think that there's a situation that is potentially quite confusing: * In the statement self.x = self.x + 1, the two self.x names can sometimes refer to different objects. But this is

Re: Style question - defining immutable class data members

2009-03-15 Thread John Posner
Earlier, I said: I'll look into what the standard Python doc set says on this matter. RTFM, in section Augmented assignment statements of python301.chm: --- For targets which are attribute references, the initial value is retrieved with a getattr() and the result is assigned with a

Re: Style question - defining immutable class data members

2009-03-15 Thread Rhodri James
On Sun, 15 Mar 2009 23:26:04 -, Aaron Brady castiro...@gmail.com wrote: On Mar 15, 1:50 pm, Rhodri James rho...@wildebst.demon.co.uk wrote: On Sun, 15 Mar 2009 17:55:25 -, Aaron Brady castiro...@gmail.com   wrote: On Mar 15, 12:39 pm, John Posner jjpos...@snet.net wrote: (My

Re: Style question - defining immutable class data members

2009-03-15 Thread Tim Wintle
On Sun, 2009-03-15 at 10:39 -0700, John Posner wrote: (My apologies if the thread has already covered this.) I believe I understand the WHAT in this situation, but I don't understand the WHY ... Is there a beneficial effect of silently creating the instance attribute, which outweighs the

Re: Style question - defining immutable class data members

2009-03-15 Thread Tim Wintle
On Mon, 2009-03-16 at 04:02 +, Tim Wintle wrote: On Sun, 2009-03-15 at 10:39 -0700, John Posner wrote: Doh, reply out of thread there - I meant to reply to Rhodi's comment further down. Is there any actual advantage to self.attribute picking up Class.attribute instead of raising a

Re: Style question - defining immutable class data members

2009-03-15 Thread Gary Herron
John Posner wrote: (My apologies if the thread has already covered this.) I believe I understand the WHAT in this situation, but I don't understand the WHY ... Given this class definition: class Cls(object): x = 345 ... I observe the following, using IDLE 2.6.1: inst = Cls()

Style question - defining immutable class data members

2009-03-14 Thread Maxim Khitrov
Very simple question on the preferred coding style. I frequently write classes that have some data members initialized to immutable values. For example: class Test(object): def __init__(self): self.some_value = 0 self.another_value = None Similar effect can be achieved by

Re: Style question - defining immutable class data members

2009-03-14 Thread MRAB
Maxim Khitrov wrote: Very simple question on the preferred coding style. I frequently write classes that have some data members initialized to immutable values. For example: class Test(object): def __init__(self): self.some_value = 0 self.another_value = None Similar effect

Re: Style question - defining immutable class data members

2009-03-14 Thread Maxim Khitrov
On Sat, Mar 14, 2009 at 12:50 PM, MRAB goo...@mrabarnett.plus.com wrote: Maxim Khitrov wrote: Very simple question on the preferred coding style. I frequently write classes that have some data members initialized to immutable values. For example: class Test(object):    def __init__(self):

Re: Style question - defining immutable class data members

2009-03-14 Thread bearophileHUGS
Maxim Khitrov: When the types are immutable, there is no difference. But you may want different instances to have different immutable data. Generally if the data (immutable or not) is the same for all the instances, use class attributes, otherwise use instance attributes. Bye, bearophile --

Re: Style question - defining immutable class data members

2009-03-14 Thread Gary Herron
Maxim Khitrov wrote: Very simple question on the preferred coding style. I frequently write classes that have some data members initialized to immutable values. For example: class Test(object): def __init__(self): self.some_value = 0 self.another_value = None Similar effect

Re: Style question - defining immutable class data members

2009-03-14 Thread Terry Reedy
Maxim Khitrov wrote: On Sat, Mar 14, 2009 at 12:50 PM, MRAB goo...@mrabarnett.plus.com wrote: Maxim Khitrov wrote: Very simple question on the preferred coding style. I frequently write classes that have some data members initialized to immutable values. For example: class Test(object):

Re: Style question - defining immutable class data members

2009-03-14 Thread Maxim Khitrov
On Sat, Mar 14, 2009 at 2:07 PM, Gary Herron gher...@islandtraining.com wrote: Maxim Khitrov wrote: Very simple question on the preferred coding style. I frequently write classes that have some data members initialized to immutable values. For example: class Test(object):    def

Re: Style question - defining immutable class data members

2009-03-14 Thread David Stanek
On Sat, Mar 14, 2009 at 12:32 PM, Maxim Khitrov mkhit...@gmail.com wrote: Very simple question on the preferred coding style. I frequently write classes that have some data members initialized to immutable values. For example: class Test(object):    def __init__(self):        

Re: Style question - defining immutable class data members

2009-03-14 Thread Gary Herron
Maxim Khitrov wrote: On Sat, Mar 14, 2009 at 2:07 PM, Gary Herron gher...@islandtraining.com wrote: Maxim Khitrov wrote: Very simple question on the preferred coding style. I frequently write classes that have some data members initialized to immutable values. For example: class

Re: Style question - defining immutable class data members

2009-03-14 Thread Terry Reedy
Maxim Khitrov wrote: Perhaps a different example would help explain what I'm trying to do: class Case1(object): def __init__(self): self.count = 0 self.list = [] def inc(self): self.count += 1

Re: Style question - defining immutable class data members

2009-03-14 Thread Matthew Woodcraft
Gary Herron gher...@islandtraining.com writes: But now you are not listening to what people are telling you. It has *nothing* to do with the mutability/immutability of the integer and the list your two classes create. No! Did you run the code he posted? The immutability makes all the

Re: Style question - defining immutable class data members

2009-03-14 Thread Maxim Khitrov
On Sat, Mar 14, 2009 at 4:31 PM, Gary Herron gher...@islandtraining.com wrote: Perhaps a different example would help explain what I'm trying to do: class Case1(object):        def __init__(self):                self.count = 0                self.list  = []        def inc(self):          

Re: Style question - defining immutable class data members

2009-03-14 Thread Maxim Khitrov
On Sat, Mar 14, 2009 at 5:38 PM, Matthew Woodcraft matt...@woodcraft.me.uk wrote: Gary Herron gher...@islandtraining.com writes: I think this code is in poor taste: it's clear that it will confuse people (which is what Maxim was asking about in the first place). Yes, I see that now, thanks :)

Re: Style question - defining immutable class data members

2009-03-14 Thread Torsten Bronger
Hallöchen! Maxim Khitrov writes: [...] The advantage of doing this is that the assignments are evaluated once and thus the creation of that class is a bit faster. Access is still performed through self.some_value and self.another_value. Is there a reason to prefer the first style over the

Re: Style question - defining immutable class data members

2009-03-14 Thread Gary Herron
Maxim Khitrov wrote: On Sat, Mar 14, 2009 at 4:31 PM, Gary Herron gher...@islandtraining.com wrote: Perhaps a different example would help explain what I'm trying to do: class Case1(object): def __init__(self): self.count = 0 self.list = [] def

Re: Style question - defining immutable class data members

2009-03-14 Thread Gary Herron
Maxim Khitrov wrote: On Sat, Mar 14, 2009 at 5:38 PM, Matthew Woodcraft matt...@woodcraft.me.uk wrote: Gary Herron gher...@islandtraining.com writes: I think this code is in poor taste: it's clear that it will confuse people (which is what Maxim was asking about in the first place).

Python Style Question

2009-01-22 Thread K-Dawg
I am trying to become more pythonic as I learn python and get my mind around it instead of other languages I have used. I have an app that has a series of classes for objects it uses. From a style perspective, which should be done: Different py file for each class or One py file with all the

Re: Python Style Question

2009-01-22 Thread Steve Holden
K-Dawg wrote: I am trying to become more pythonic as I learn python and get my mind around it instead of other languages I have used. I have an app that has a series of classes for objects it uses. From a style perspective, which should be done: Different py file for each class or

Re: Python Style Question

2009-01-22 Thread Terry Reedy
Steve Holden wrote: K-Dawg wrote: I am trying to become more pythonic as I learn python and get my mind around it instead of other languages I have used. I have an app that has a series of classes for objects it uses. From a style perspective, which should be done: Different py file for each

style question - hasattr

2008-04-08 Thread ian
In old python code i would use 'has_key' to determine if an element was present in a dictionary. Python 3.0 will even removed 'has_key'. The reason for removal is that using the 'in' operator is a cleaner syntax and having two ways to achieve the same result is against the principle of the

Re: style question - hasattr

2008-04-08 Thread Terry Reedy
ian [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | In old python code i would use 'has_key' to determine if an element | was present in a dictionary. | | Python 3.0 will even removed 'has_key'. The reason for removal is that | using the 'in' operator is a cleaner syntax and having

Re: style question - hasattr

2008-04-08 Thread Miles
On Tue, Apr 8, 2008 at 10:21 PM, ian [EMAIL PROTECTED] wrote: Ok, so what about 'hasattr' ?? hasattr(myObject,'property') seems equivalent to 'property' in dir(myObject) I would suggest that using the 'in' is cleaner in this case also. Is there a performance penalty here? Or is

Re: docstrings style question

2008-01-10 Thread Russ P.
On Jan 9, 11:51 pm, Fredrik Lundh [EMAIL PROTECTED] wrote: Steve Brown wrote: I've got a series of modules which look like this: # # # Temperature Sense Test # # class Test3(ar_test.AR_TEST): Temperature Sense Test I don't like the duplicated

Re: docstrings style question

2008-01-10 Thread Jeroen Ruigrok van der Werven
-On [20080110 06:51], Steve Brown ([EMAIL PROTECTED]) wrote: I don't like the duplicated information: But the comment is attractive, I find it unattractive to be honest. and the docstring self.__doc__ is already in use in the test log. I've read that all modules and classes should have

RE: docstrings style question

2008-01-10 Thread Ryan Ginstrom
On Behalf Of Steve Brown What do you think? I think that comments are for maintainers, and docstrings are for users. Some of the things I use comments for: * Visually separate classes (using a syntax-highlighting editor) * Explain algorithm choices * Explain bug fixes so I don't later fix

Re: docstrings style question

2008-01-10 Thread Martin Marcher
Russ P. wrote: On Jan 9, 9:47 pm, Steve Brown [EMAIL PROTECTED] wrote: I've got a series of modules which look like this: # # # Temperature Sense Test # # class Test3(ar_test.AR_TEST): Temperature Sense Test I don't like the duplicated information: But the

Re: docstrings style question

2008-01-10 Thread Steve Brown
Russ P. [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Jan 9, 11:51 pm, Fredrik Lundh [EMAIL PROTECTED] wrote: Steve Brown wrote: I've got a series of modules which look like this: # # # Temperature Sense Test # # class

Re: docstrings style question

2008-01-10 Thread Neil Cerutti
On Jan 10, 2008 12:47 AM, Steve Brown [EMAIL PROTECTED] wrote: I've got a series of modules which look like this: # # # Temperature Sense Test # # class Test3(ar_test.AR_TEST): Temperature Sense Test I don't like the duplicated information: But the comment

Re: docstrings style question

2008-01-10 Thread Steve Brown
Neil Cerutti [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Jan 10, 2008 12:47 AM, Steve Brown [EMAIL PROTECTED] wrote: I've got a series of modules which look like this: # # # Temperature Sense Test # # class Test3(ar_test.AR_TEST):

Re: docstrings style question

2008-01-10 Thread Steve Brown
What I'm trying to do with the tests is pare them back so that the code explicitly and concisely documents the tests. It is important that the comments and doc strings NOT contain information about how Temperature Sense works because that is outside the scope of the test. More generally,

Re: docstrings style question

2008-01-10 Thread Steven D'Aprano
On Fri, 11 Jan 2008 13:09:26 +1100, Steve Brown wrote: What I'm trying to do with the tests is pare them back so that the code explicitly and concisely documents the tests. Yes, this is good. It is important that the comments and doc strings NOT contain information about how Temperature

docstrings style question

2008-01-09 Thread Steve Brown
I've got a series of modules which look like this: # # # Temperature Sense Test # # class Test3(ar_test.AR_TEST): Temperature Sense Test I don't like the duplicated information: But the comment is attractive, and the docstring self.__doc__ is already in use in the

Re: docstrings style question

2008-01-09 Thread Fredrik Lundh
Steve Brown wrote: I've got a series of modules which look like this: # # # Temperature Sense Test # # class Test3(ar_test.AR_TEST): Temperature Sense Test I don't like the duplicated information: But the comment is attractive, and the docstring

Re: style question

2006-07-04 Thread Terry Hancock
Hari Sekhon wrote: Is it better to do: message = This is line1. This is line2 This is line3\n or message = This is line1.\n message = message + This is line2\n message = message + This is line3\n Since the first method does not follow python's clean and easy looking indentation

Re: style question

2006-07-01 Thread Jorgen Grahn
On Thu, 29 Jun 2006 15:31:53 -0700, Scott David Daniels [EMAIL PROTECTED] wrote: ... I like well-typeset code in print though. Bjarne Stroustrup uses an elegant system for C++ code, See Knuth on Literate Programming and the Web systems (e.g. CWeb). His goal is to look good typeset with

Re: style question

2006-07-01 Thread Jorgen Grahn
On Thu, 29 Jun 2006 23:19:34 +0200, Fredrik Lundh [EMAIL PROTECTED] wrote: Jorgen Grahn wrote: assuming fixed-pitch fonts isn't very Pythonic, though; to get reliable indentation no matter what font you're using, you can write [...] Since when? I've always coded, in all languages I've

Non-ASCII languages (was: Re: style question)

2006-07-01 Thread Jorgen Grahn
On Thu, 29 Jun 2006 23:19:34 +0200, Fredrik Lundh [EMAIL PROTECTED] wrote: Jorgen Grahn wrote: ... (I like well-typeset code in print though. Bjarne Stroustrup uses an elegant system for C++ code, where identifiers and strings are in Times italic, operators in Courier, and so on.) the idea

Re: Non-ASCII languages (was: Re: style question)

2006-07-01 Thread Nick Maclaren
In article [EMAIL PROTECTED], Jorgen Grahn [EMAIL PROTECTED] writes: | | Possibly true, and definitely for Knuth. But WYSIWYG was unknown at the | time; these people all programmed using fixed-width fonts, on teletypes or | character-mapped terminals. Hell, even full-screen editors were new and

Re: style question

2006-06-29 Thread Jorgen Grahn
On Mon, 26 Jun 2006 11:47:21 +0200, Fredrik Lundh [EMAIL PROTECTED] wrote: ... assuming fixed-pitch fonts isn't very Pythonic, though; to get reliable indentation no matter what font you're using, you can write [...] Since when? I've always coded, in all languages I've ever used[1], under

Re: style question

2006-06-29 Thread Fredrik Lundh
Jorgen Grahn wrote: assuming fixed-pitch fonts isn't very Pythonic, though; to get reliable indentation no matter what font you're using, you can write [...] Since when? I've always coded, in all languages I've ever used[1], under the assumption that the reader will view it with a

Re: style question

2006-06-29 Thread Scott David Daniels
Jorgen Grahn wrote: On Mon, 26 Jun 2006 11:47:21 +0200, Fredrik Lundh [EMAIL PROTECTED] wrote: ... assuming fixed-pitch fonts isn't very Pythonic, though; to get reliable indentation no matter what font you're using, you can write [...] Since when? I've always coded, in all languages

Re: style question

2006-06-27 Thread Hari Sekhon
On 26/06/06, Claudio Grondi [EMAIL PROTECTED] wrote: Scott David Daniels wrote: Claudio Grondi wrote: clever stuff to di indentation When necessary to skip first line _and_ indentation: message = This is line 1 This is line 2 This is line 3 .replace('\n', '\n')[1:] # adjust here '\n' to

Re: style question

2006-06-27 Thread Hari Sekhon
Claudio Grondi wrote: Hari Sekhon wrote: On 26/06/06, *Claudio Grondi* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Scott David Daniels wrote: Claudio Grondi wrote: clever stuff to di indentation When necessary to skip first line _and_ indentation:

style question

2006-06-26 Thread Hari Sekhon
Is it better to do: message = This is line1. This is line2 This is line3\n or message = This is line1.\n message = message + This is line2\n message = message + This is line3\n Since the first method does not follow python's clean and easy looking indentation structure but the second just

Re: style question

2006-06-26 Thread MTD
Hari Sekhon wrote: Is it better to do: message = This is line1. This is line2 This is line3\n or message = This is line1.\n message = message + This is line2\n message = message + This is line3\n Is there any reason you can't do it in one line? message = This is line1.\nThis is

Re: style question

2006-06-26 Thread Hari Sekhon
MTD wrote: Hari Sekhon wrote: Is it better to do: message = """This is line1. This is line2 This is line3\n""" or message = "This is line1.\n message = message + "This is line2\n" message = message + "This is line3\n" Is there any reason you can't do it in one line?

<    1   2   3   >