Re: [Tutor] properties beginner M Dawson book

2012-06-11 Thread Alan Gauld
On 11/06/12 16:05, brian arb wrote: Highly recommend writing unittest, each unit test sends a specific input to a method and verifies that the method returns the expected value, or takes the expected action. Unit tests prove that the code you are testing does in fact do what you expect it to do.

Re: [Tutor] properties beginner M Dawson book

2012-06-11 Thread Mark Lawrence
On 11/06/2012 16:05, brian arb wrote: I would look into pylint, Python source code looking for bugs and signs of poor quality. Or pychecker or pyflakes. -- Cheers. Mark Lawrence. ___ Tutor maillist - Tutor@python.org To unsubscribe or change sub

Re: [Tutor] properties beginner M Dawson book

2012-06-11 Thread brian arb
I'm a bad fan of Nick Parlante teaching style. He has a excellent site that has some exercises to teach Python, and they are backed with unittests. http://codingbat.com/python On Mon, Jun 11, 2012 at 11:05 AM, brian arb wrote: > I would look into pylint, Python sou

Re: [Tutor] properties beginner M Dawson book

2012-06-11 Thread brian arb
I would look into pylint, Python source code looking for bugs and signs of poor quality. > There are, unfortunately, no answers nor examples of good and bad code. > Honestly I don’t want to “cheat” but I have to teach Python to some young > students in September, using this book, and I want all

Re: [Tutor] properties beginner M Dawson book

2012-06-11 Thread Emile van Sebille
On 6/10/2012 4:58 AM Steven D'Aprano said... Nicholas Harman wrote: I have done a little programming in BlueJ Java before but I decided to try the “Python style” as explained in the chapter, using properties rather than variables and getters and setters . My main question is: When using pro

Re: [Tutor] properties beginner M Dawson book

2012-06-10 Thread Steven D'Aprano
Nicholas Harman wrote: class Television(object): #Contstructor Spelling error: Constructor. Actually, technically __init__ is not the constructor. __init__ is the initializer, as the object has already been created before __init__ is called. __new__ is the constructor, although in this

Re: [Tutor] properties beginner M Dawson book

2012-06-10 Thread Steven D'Aprano
Nicholas Harman wrote: I have done a little programming in BlueJ Java before but I decided to try the “Python style” as explained in the chapter, using properties rather than variables and getters and setters . My main question is: When using property and setter it seems I must use “__name”

Re: [Tutor] Properties of an object

2009-01-30 Thread Alan Gauld
"Eike Welk" wrote In a rather consistent approach, Python does not provide any standard way to simply define/describe/structure an object -- or a class. The added flexibility of Python gives great powers to the programmers of libraries. It goves a lot of flexibility, whether that really is

Re: [Tutor] Properties of an object

2009-01-30 Thread ALAN GAULD
> Python 2.x can add new methods to a user-defined class or instance or > redefine existing methods. > In [6]: def sayFoo(self): print 'foo' > > In [7]: Data.sayFoo = sayFoo > > In [8]: d1.sayFoo() > foo > Now for some reason I was sure that didn't work. So sure I never even tried! (despite

Re: [Tutor] Properties of an object

2009-01-30 Thread Eike Welk
Hello Spir! On Friday 30 January 2009, spir wrote: > In a rather consistent approach, Python does not provide any > standard way to simply define/describe/structure an object -- or a > class. The added flexibility of Python gives great powers to the programmers of libraries. There is for examp

Re: [Tutor] Properties of an object

2009-01-30 Thread Kent Johnson
On Fri, Jan 30, 2009 at 3:50 PM, Alan Gauld wrote: > "spir" wrote > >> I was not thinking at data hiding or protection, rather at object >> structure >> (or behaviour) specification. First, to the human -- and alse to the >> machine. > > Ah, OK, then in that case I am happier to agree that Python

Re: [Tutor] Properties of an object

2009-01-30 Thread Alan Gauld
"spir" wrote I was not thinking at data hiding or protection, rather at object structure (or behaviour) specification. First, to the human -- and alse to the machine. Ah, OK, then in that case I am happier to agree that Python is unusual (although not unique - Lisp can do the same) in its ab

Re: [Tutor] Properties of an object

2009-01-30 Thread spir
Le Fri, 30 Jan 2009 19:05:40 -, "Alan Gauld" a écrit : > "spir" wrote > > > There is no real native support for ordinary OOP in python, meaning > > as is done in most other languages, or according to the theory. > > I have to disagree. I think you are confusing OOP with C++ and Java. > The

Re: [Tutor] Properties of an object

2009-01-30 Thread Alan Gauld
"spir" wrote There is no real native support for ordinary OOP in python, meaning as is done in most other languages, or according to the theory. I have to disagree. I think you are confusing OOP with C++ and Java. The early OOP languages had a variety of approaches to this. Several took the s

Re: [Tutor] Properties of an object

2009-01-30 Thread Vicent
On Fri, Jan 30, 2009 at 12:43, Kent Johnson wrote: > > A note on terminology: In Python, what you are describing is called an > attribute. 'property' has a very specific meaning, it is a way to > associate a value with an instance that uses attribute notation for > access, i.e. a.b, but actually

Re: [Tutor] Properties of an object

2009-01-30 Thread spir
Le Fri, 30 Jan 2009 12:22:10 +0100, Vicent a écrit : > Thanks to all for your clear answers. I learned a lot about the way Python > manages properties or attributes. > > In my particular case, I think, as Spir said, that the best implementation > depends on wether I am going to update the "base"

Re: [Tutor] Properties of an object

2009-01-30 Thread Kent Johnson
On Thu, Jan 29, 2009 at 1:59 PM, Vicent wrote: > This is an easy question, I guess, but I am not able to find out the answer. > > In fact, it is both a Python question and a general programming "style" > question. > > I want to define a class that contains a list (or a NumPy array) of elements > o

Re: [Tutor] Properties of an object

2009-01-30 Thread Vicent
Thanks to all for your clear answers. I learned a lot about the way Python manages properties or attributes. In my particular case, I think, as Spir said, that the best implementation depends on wether I am going to update the "base" properties very often or not, and wether I am going to access "t

Re: [Tutor] Properties of an object

2009-01-29 Thread Jervis Whitley
> > > > For me, the "()" look like artificial, not necessary. I would prefer just > to type"a.list_1stpart" , a property. > > > > -- > > Others have explained their preference for using get methods for accessing internal data structures, However it does look like you have specifically mention

Re: [Tutor] Properties of an object

2009-01-29 Thread Alan Gauld
"Vicent" wrote This is an easy question, I guess, but I am not able to find out the answer. Or in fact a series of not so easy questions! :-) Andre has already answered most of them but I'll add a few extras. (1) Where are the right places to define PROPERTIES for my class, and how (I mea

Re: [Tutor] Properties of an object

2009-01-29 Thread spir
Le Thu, 29 Jan 2009 19:59:09 +0100, Vicent a écrit : > This is an easy question, I guess, but I am not able to find out the answer. > > In fact, it is both a Python question and a general programming "style" > question. > > I want to define a class that contains a list (or a NumPy array) of ele

Re: [Tutor] Properties of an object

2009-01-29 Thread Andre Engels
On Thu, Jan 29, 2009 at 7:59 PM, Vicent wrote: > This is an easy question, I guess, but I am not able to find out the answer. > > In fact, it is both a Python question and a general programming "style" > question. > > I want to define a class that contains a list (or a NumPy array) of elements > o

Re: [Tutor] Properties

2007-06-08 Thread Kent Johnson
Kent Johnson wrote: > I don't know of any good introductory material on properties but here > are some starting points: > http://www.python.org/download/releases/2.2/descrintro/#property > http://docs.python.org/lib/built-in-funcs.html#l2h-57 Here is another: http://users.rcn.com/python/download/

Re: [Tutor] Properties

2007-06-07 Thread Kent Johnson
Greg Lindstrom wrote: > Hello, and I apologize in advance for the question. No apologies needed, this list would be quite boring without any questions :-) > > I have decided to publish a class I use to handle data segments to > Google Code for the world to see (I plan to make millions off train

Re: [Tutor] properties and subclasses

2005-04-27 Thread Kent Johnson
Max Noel wrote: Speaking of that, would you happen to know a good tutorial/introduction to metaclasses in Python? Here is an example that bills itself as "The Simplest Possible Metaclass": http://orbtech.com/blog/simplemetaclass The new Python Cookbook (the printed one) has a chapter on Descri

Re: [Tutor] properties and subclasses

2005-04-27 Thread Alan Gauld
> > Once you get used to them meta-classes are very useful. In fact I have > > never built an industrial size OO system yet that did not use meta > > classes somewhere in the design... > > Speaking of that, would you happen to know a good > tutorial/introduction to metaclasses in Python? Nope, bu

Re: [Tutor] properties and subclasses

2005-04-26 Thread Kent Johnson
Max Noel wrote: Speaking of that, would you happen to know a good tutorial/introduction to metaclasses in Python? You could try Guido's essay: http://www.python.org/2.2/descrintro.html#metaclasses Kent ___ Tutor maillist - Tutor@python.org http://m

Re: [Tutor] properties and subclasses

2005-04-26 Thread Max Noel
On Apr 26, 2005, at 22:01, Alan Gauld wrote: I had found the first thread you linked. I see what you mean about the cure -- my general belief is that *I* am unlikely to have problems for which meta-classes are really the best solution :-) Once you get used to them meta-classes are very useful. In

Re: [Tutor] properties and subclasses

2005-04-26 Thread Brian van den Broek
Alan Gauld said unto the world upon 2005-04-26 17:01: I had found the first thread you linked. I see what you mean about the cure -- my general belief is that *I* am unlikely to have problems for which meta-classes are really the best solution :-) Once you get used to them meta-classes are very u

Re: [Tutor] properties and subclasses

2005-04-26 Thread Alan Gauld
> I had found the first thread you linked. I see what you mean about the > cure -- my general belief is that *I* am unlikely to have problems > for which meta-classes are really the best solution :-) Once you get used to them meta-classes are very useful. In fact I have never built an industrial

Re: [Tutor] properties and subclasses

2005-04-26 Thread Brian van den Broek
Kent Johnson said unto the world upon 2005-04-26 06:24: Brian van den Broek wrote: Hi all, I'm trying to get a hang of properties. It isn't quite clear to me what is the best way to make properties differ in subclasses. Some code snips to show what I've tried: I can get what I want this way: class

Re: [Tutor] properties and subclasses

2005-04-26 Thread Kent Johnson
Brian van den Broek wrote: Hi all, I'm trying to get a hang of properties. It isn't quite clear to me what is the best way to make properties differ in subclasses. Some code snips to show what I've tried: I can get what I want this way: class A(object): ... def __init__(self): pass ... def