Re: [Tutor] class method problem

2010-09-25 Thread Steven D'Aprano
On Sun, 26 Sep 2010 08:13:23 am David Hutto wrote: Since I had nothing else to do, but practice, this looks much better: def find(word, search): if search in word: print True else: print False For some definition of better. If I called a function:

Re: [Tutor] class method problem

2010-09-25 Thread David Hutto
On Sat, Sep 25, 2010 at 9:16 PM, Steven D'Aprano st...@pearwood.info wrote: On Sun, 26 Sep 2010 08:13:23 am David Hutto wrote: Since I had nothing else to do, but practice, this looks much better: def find(word, search):       if search in word:               print True       else:        

Re: [Tutor] class function problem

2010-09-22 Thread Hugo Arts
On Wed, Sep 22, 2010 at 9:10 AM, Roelof Wobben rwob...@hotmail.com wrote: HEllo, I have this exercise : 3.Rewrite the increment function so that it doesn’t contain any loops. The increment function looks like this : def increment(time, seconds):    time.seconds = time.seconds + seconds

Re: [Tutor] class function problem

2010-09-22 Thread Roelof Wobben
From: hugo.yo...@gmail.com Date: Wed, 22 Sep 2010 16:16:45 +0200 Subject: Re: [Tutor] class function problem To: rwob...@hotmail.com CC: tutor@python.org On Wed, Sep 22, 2010 at 9:10 AM, Roelof Wobben wrote: HEllo, I have this exercise : 3

Re: [Tutor] class function problem

2010-09-22 Thread Hugo Arts
On Wed, Sep 22, 2010 at 5:17 PM, Roelof Wobben rwob...@hotmail.com wrote: That's very clever. But you might argue that recursion is technically still a loop, albeit an implicit one. There is a simpler way to do this, without loops entirely. Hint: repeated subtraction while your number is

Re: [Tutor] class function problem

2010-09-22 Thread Steven D'Aprano
On Thu, 23 Sep 2010 01:17:59 am Roelof Wobben wrote: Sorry. I don't get it. When I have 62 seconds that's 1 minutes and 2 seconds. I have no clue how I can this with a division. If you have 60 seconds, you have one minute. If you have 120 minutes, you have two minutes. Can you get from 120

Re: [Tutor] class function problem

2010-09-22 Thread Steven D'Aprano
On Thu, 23 Sep 2010 05:55:36 am Steven D'Aprano wrote: You will find the divmod() function useful. divmod(a, b) returns two numbers: a/b as a whole number, any remainder left only Arggh! Of course I meant any reminder left OVER. -- Steven D'Aprano

Re: [Tutor] class problem

2010-09-18 Thread Alan Gauld
Roelof Wobben rwob...@hotmail.com wrote Create and print a Point object, and then use id to print the object’s unique identifier. Translate the hexadecimal form into decimal and confirm that they match. I initially had no idea what hexadecimal form the text is talking about. id returns a

Re: [Tutor] class problem

2010-09-18 Thread Steven D'Aprano
On Sat, 18 Sep 2010 07:14:03 pm Roelof Wobben wrote: P=(Point) This line does not do what you think it does. Brackets in Python are used for two things, grouping and calling functions. To call a function, or a class, you need to have the brackets *after* the function: P = Point() # what

Re: [Tutor] class questions

2010-06-27 Thread Hugo Arts
On Sun, Jun 27, 2010 at 2:09 AM, Steven D'Aprano st...@pearwood.info wrote: On Sun, 27 Jun 2010 03:05:16 am Payal wrote: Can you give any simple example where this simple mro will work incorrectly? Probably not... it's quite complicated, which is why it's rare. I'll have a think about it

Re: [Tutor] class questions

2010-06-27 Thread Payal
Hi Hugo, On Sun, Jun 27, 2010 at 01:27:37PM +0200, Hugo Arts wrote: Here's my attempt. Consider this simple Diamond hierarchy: [...] Now, with this diagram the following code probably doesn't do what you expect: Actually, it does what is expected. The old mro specifically says, bottom-top,

Re: [Tutor] class questions

2010-06-27 Thread Payal
Hi Steven, Thanks a lot for patiently explaining the concepts. I uderstood most of it. With warm regards, -Payal -- On Sun, Jun 27, 2010 at 10:09:38AM +1000, Steven D'Aprano wrote: Probably not... it's quite complicated, which is why it's rare. I'll have a think about it and see what I can

Re: [Tutor] class questions

2010-06-27 Thread Hugo Arts
On Sun, Jun 27, 2010 at 4:13 PM, Payal payal-pyt...@scriptkitchen.com wrote: Hi Hugo, On Sun, Jun 27, 2010 at 01:27:37PM +0200, Hugo Arts wrote: Here's my attempt. Consider this simple Diamond hierarchy: [...] Now, with this diagram the following code probably doesn't do what you expect:

Re: [Tutor] class questions

2010-06-27 Thread Shashwat Anand
snip The problem of the MRO isn't that it doesn't work, it's that it causes behavior that is unintuitive. In my example, We would expect D.x to be equal to C.x (since D inherits from C, and C overrides the x method). However, this is not the case. This is what the problem is with the old MRO

Re: [Tutor] class questions

2010-06-27 Thread Hugo Arts
On Sun, Jun 27, 2010 at 6:47 PM, Shashwat Anand anand.shash...@gmail.com wrote: snip The problem of the MRO isn't that it doesn't work, it's that it causes behavior that is unintuitive. In my example, We would expect D.x to be equal to C.x (since D inherits from C, and C overrides the x

Re: [Tutor] class questions

2010-06-26 Thread Steven D'Aprano
On Sat, 26 Jun 2010 10:17:45 pm Payal wrote: Hi, Some questions about which I am a bit confused. 1. I know there is a difference between mro of classic and new style classes. but I do not get why we need the new mro, the old one is easy to predict and understand? The old MRO (Method

Re: [Tutor] class questions

2010-06-26 Thread Payal
Thanks a lot for the quick answer. Still some doubts below. On Sat, Jun 26, 2010 at 11:07:17PM +1000, Steven D'Aprano wrote: The old MRO (Method Resolution Order) is broken for classes using multiple inheritance with a diamond shape inheritance diagram. Not a little bit broken, but horribly,

Re: [Tutor] class questions

2010-06-26 Thread Eike Welk
Hello Payal! On Saturday June 26 2010 19:05:16 Payal wrote: Can we say that our own exception classes have only maybe a doc-string and pass, nothing more? No, you let the exception transport the information that you need for handling the error. This is an exception that I use to transport

Re: [Tutor] class questions

2010-06-26 Thread Christopher King
Well the application of defining ones own error is in a module. For example, if I make a banking account module, I might define a WithdrawError if there is a place where a error might occur. That way if client code tries to withdraw too much, you can have a very descriptive error making it easier

Re: [Tutor] class questions

2010-06-26 Thread Christopher King
only new classes can have properties, a major tool On Sat, Jun 26, 2010 at 8:17 AM, Payal payal-pyt...@scriptkitchen.comwrote: Hi, Some questions about which I am a bit confused. 1. I know there is a difference between mro of classic and new style classes. but I do not get why we need the

Re: [Tutor] class questions

2010-06-26 Thread Steven D'Aprano
On Sun, 27 Jun 2010 03:05:16 am Payal wrote: Thanks a lot for the quick answer. Still some doubts below. On Sat, Jun 26, 2010 at 11:07:17PM +1000, Steven D'Aprano wrote: The old MRO (Method Resolution Order) is broken for classes using multiple inheritance with a diamond shape inheritance

Re: [Tutor] class methods as static methods?

2010-05-30 Thread Alan Gauld
Alex Hall mehg...@gmail.com wrote that it will hit. I would like to not instantiate a Harpoon object, just call the Harpoon's getImpactCoords method and pass it the required arguments. Is this possible? Others have pointed out that a) This is possible using staticmetjhod or classmetjod

Re: [Tutor] class methods as static methods?

2010-05-30 Thread Alex Hall
On 5/30/10, Alan Gauld alan.ga...@btinternet.com wrote: Alex Hall mehg...@gmail.com wrote that it will hit. I would like to not instantiate a Harpoon object, just call the Harpoon's getImpactCoords method and pass it the required arguments. Is this possible? Others have pointed out that a)

Re: [Tutor] class methods as static methods?

2010-05-29 Thread Lie Ryan
On 05/30/10 05:49, Alex Hall wrote: Hi all, In Battleship, I have a weapons.py file, currently with just one missile type (a Harpoon anti-ship missile). This Harpoon class defines a getImpactCoords method, which returns all coordinates on the map that it will hit. I would like to not

Re: [Tutor] class methods as static methods?

2010-05-29 Thread Mark Lawrence
On 29/05/2010 20:49, Alex Hall wrote: Hi all, In Battleship, I have a weapons.py file, currently with just one missile type (a Harpoon anti-ship missile). This Harpoon class defines a getImpactCoords method, which returns all coordinates on the map that it will hit. I would like to not

Re: [Tutor] class methods as static methods?

2010-05-29 Thread Alex Hall
On 5/29/10, Mark Lawrence breamore...@yahoo.co.uk wrote: On 29/05/2010 20:49, Alex Hall wrote: Hi all, In Battleship, I have a weapons.py file, currently with just one missile type (a Harpoon anti-ship missile). This Harpoon class defines a getImpactCoords method, which returns all

Re: [Tutor] class methods as static methods?

2010-05-29 Thread Steven D'Aprano
On Sun, 30 May 2010 05:49:45 am Alex Hall wrote: Hi all, In Battleship, I have a weapons.py file, currently with just one missile type (a Harpoon anti-ship missile). This Harpoon class defines a getImpactCoords method, which returns all coordinates on the map that it will hit. I would like to

Re: [Tutor] class methods as static methods?

2010-05-29 Thread Mark Lawrence
Hi Alex, thanks for the response, please see below. On 30/05/2010 02:50, Alex Hall wrote: On 5/29/10, Mark Lawrencebreamore...@yahoo.co.uk wrote: On 29/05/2010 20:49, Alex Hall wrote: Hi all, In Battleship, I have a weapons.py file, currently with just one missile type (a Harpoon anti-ship

Re: [Tutor] class methods: using class vars as args?

2010-05-28 Thread Steven D'Aprano
On Fri, 28 May 2010 07:42:30 am Alex Hall wrote: Thanks for all the explanations, everyone. This does make sense, and I am now using the if(arg==None): arg=self.arg idea. It only adds a couple lines, and is, if anything, more explicit than what I was doing before. You should use if arg is

Re: [Tutor] class methods: using class vars as args?

2010-05-27 Thread spir ☣
On Sun, 23 May 2010 15:40:13 -0400 Alex Hall mehg...@gmail.com wrote: Hello all, I know Python reasonably well, but I still run into basic questions which those over on the other python list request I post here instead. I figure this would be one of them: Why would this not work: class

Re: [Tutor] class methods: using class vars as args?

2010-05-27 Thread Mark Lawrence
On 23/05/2010 20:40, Alex Hall wrote: Hello all, I know Python reasonably well, but I still run into basic questions which those over on the other python list request I post here instead. I figure this would be one of them: Why would this not work: class c(object): def __init__(self, arg1,

Re: [Tutor] class methods: using class vars as args?

2010-05-27 Thread Alex Hall
Thanks for all the explanations, everyone. This does make sense, and I am now using the if(arg==None): arg=self.arg idea. It only adds a couple lines, and is, if anything, more explicit than what I was doing before. On 5/27/10, Mark Lawrence breamore...@yahoo.co.uk wrote: On 23/05/2010 20:40,

Re: [Tutor] class methods: using class vars as args?

2010-05-23 Thread Alan Gauld
Alex Hall mehg...@gmail.com wrote class c(object): def __init__(self, arg1, arg2): self.arg1=arg1 self.arg2=arg2 def doSomething(self, arg3=self.arg1): ... The above results in an error that name 'self' is not defined. Why can I not set the default values of a method's arguments to class

Re: [Tutor] class methods: using class vars as args?

2010-05-23 Thread Matthew Wood
Hey Alex, What's happening is that you're still in defining functions mode on the line def doSomething(self, arg3=self.arg1): self, which is really nothing more than a parameter being passed in (special parameter, but a parameter none the less) hasn't been assigned a value yet. Imagine this

Re: [Tutor] Class Inheritance, Beat it into the Ground

2010-04-24 Thread Steven D'Aprano
On Sat, 24 Apr 2010 03:41:04 pm David Hutto wrote: In previous post I asked about turtle module importing from tkinter. But what I don't understand is why does Tkinter default it's casnvas to ScrolledCanvas in turtle.py, and then as a 'metaclass' for ScrolledCanvas in turtle it calls

Re: [Tutor] Class Inheritance, Beat it into the Ground

2010-04-24 Thread Alan Gauld
David Hutto smokefl...@gmail.com wrote In previous post I asked about turtle module importing from tkinter. But what I don't understand is why does Tkinter default it's casnvas to ScrolledCanvas in turtle.py, Tkinter doesn't. The author of the turtle module - which is not part of Tkinter

Re: [Tutor] Class Inheritance, Beat it into the Ground

2010-04-24 Thread Alan Gauld
Steven D'Aprano st...@pearwood.info wrote Yes, Tkinter could have had a ScrolledCanvas. It could have had lots of things, you have to draw the line somewhere otherwise you end up with one giant module that does *everything*: And for completeness there are a number of add-on modules in the

Re: [Tutor] Class Inheritance

2010-04-23 Thread Alan Gauld
David Hutto smokefl...@gmail.com wrote While experimenting with Tkinter(python2.6), when from Tkinter import* is used I came across the following error: File C:\Python26\lib\lib-tk\Tkinter.py, line 44, in module from turtle import * Huh? Why is Tkinter.py importing from

Re: [Tutor] Class Inheritance

2010-04-23 Thread Steven D'Aprano
On Fri, 23 Apr 2010 04:54:11 pm David Hutto wrote: [...] Something is screwy there. I believe you have broken your installation by making changes to files without having any understanding of what you are doing. My original post was incorrect: the first error should be:

Re: [Tutor] Class Inheritance

2010-04-23 Thread Steven D'Aprano
On Sat, 24 Apr 2010 01:22:54 am David Hutto wrote: I'm new, I touched the Holy lib, and didn't check to reset the original Tkinter directory before posting. Won't happen again. I'm sorry we got off on the wrong foot, you caught me at a time when I was frustrated about other things, and after

Re: [Tutor] Class Inheritance

2010-04-22 Thread Steven D'Aprano
On Fri, 23 Apr 2010 03:11:36 pm David Hutto wrote: Hello List! While experimenting with Tkinter(python2.6), when from Tkinter import* is used I came across the following error: C:\Users\ascentc:\python26/Script3.py Traceback (most recent call last): File

Re: [Tutor] Class understanding

2009-11-24 Thread Che M
Date: Tue, 24 Nov 2009 10:27:05 -0600 From: jammer10...@gmail.com To: tutor@python.org Subject: [Tutor] Class understanding Hi all... Have been attempting to understand classes... Been getting along without them for a while now and feel it's time to jump in What I want to do it

Re: [Tutor] Class understanding

2009-11-24 Thread Dave Angel
Che M wrote: Date: Tue, 24 Nov 2009 10:27:05 -0600 From: jammer10...@gmail.com To: tutor@python.org Subject: [Tutor] Class understanding Hi all... Have been attempting to understand classes... Been getting along without them for a while now and feel it's time to jump in What I want

Re: [Tutor] class initialization with a lot of parameters

2009-11-11 Thread C.T. Matsumoto
Great, I do see my objects working as functions so my OOP understanding needs development. I've got to roll this around to come up with a design which will be more OOP centered and change the code accordingly. To start I could move CompareTableList into DB. This will make a list of tables that

Re: [Tutor] class initialization with a lot of parameters

2009-11-11 Thread Alan Gauld
C.T. Matsumoto c.t.matsum...@gmail.com wrote The Table object you described I find more complicated if each table stands on its own it is decoupled from its compare partner. I suppose a function that pairs the tables, feeding a Table object to its partner Table.compare method. Kind of.

Re: [Tutor] class initialization with a lot of parameters

2009-11-11 Thread Emile van Sebille
On 11/11/2009 10:19 AM Alan Gauld said... what we actually do in Python is if number1.__eq__(number2): In other words we call the special method __eq__() of number1 passing in number2. So == is actually a method of the object on the left hand side. ... and sometimes the right hand side.

Re: [Tutor] class initialization with a lot of parameters

2009-11-11 Thread C.T. Matsumoto
Hello Alan, I see a new way to look at this design so I'm pretty excited to refactor the code. I've also been looking for an example to use 'overloading operators' as the Learn Python book calls it. I think its time to close this discussion because the parameters question has gotten much advice,

Re: [Tutor] class initialization with a lot of parameters

2009-11-10 Thread C.T. Matsumoto
This reply is also to Alan's suggestion to provide more context. The situation concerns databases, where in one schema table I've got a 'compare list'. This list provides defines 2 tables that need to be paired and then compared. Before any comparing happens I 'filter' the compare list doing

Re: [Tutor] class initialization with a lot of parameters

2009-11-10 Thread Lie Ryan
C.T. Matsumoto wrote: Hello All, I'm making a class and the parameters I'm feeding the class is getting quite large. I'm up to 8 now. Is there any rules of thumb for classes with a lot of parameters? I was thinking to put the parameters into a tuple and then in the __init__ of the class,

Re: [Tutor] class initialization with a lot of parameters

2009-11-10 Thread Dave Angel
(Removing out of sequence history) DaveA instances of that class. Better than using tuples. makes sense to make a class to hold the seven parameters, and pass two If you're passing two sets of 7 parameters to the same function, it probably ___

Re: [Tutor] class initialization with a lot of parameters

2009-11-10 Thread Alan Gauld
C.T. Matsumoto c.t.matsum...@gmail.com wrote This list provides defines 2 tables that need to be paired and then compared. So two instances of a TestTable object maybe? reference_table_name reference_dburi reference_rows test_table_name test_dburi test_rows keys Looks like two

Re: [Tutor] class initialization with a lot of parameters

2009-11-10 Thread Luke Paireepinart
On Tue, Nov 10, 2009 at 1:21 PM, Dave Angel da...@ieee.org wrote: (Removing out of sequence history) DaveA instances of that class. Better than using tuples. makes sense to make a class to hold the seven parameters, and pass two If you're passing two sets of 7 parameters to the same

Re: [Tutor] class initialization with a lot of parameters

2009-11-10 Thread Dave Angel
Luke Paireepinart wrote: On Tue, Nov 10, 2009 at 1:21 PM, Dave Angel da...@ieee.org wrote: (Removing out of sequence history) DaveA instances of that class. Better than using tuples. makes sense to make a class to hold the seven parameters, and pass two If you're passing two sets of 7

Re: [Tutor] class initialization with a lot of parameters

2009-11-10 Thread C.T. Matsumoto
Thanks for the ideas, I see I still don't have the hang of this context thing! I still haven't provided enough context. So here goes again, to show the entire chain. This might change the discussion to be about design practice but it will give overview of how I'm using the class in question.

Re: [Tutor] class initialization with a lot of parameters

2009-11-09 Thread Alan Gauld
C.T. Matsumoto c.t.matsum...@gmail.com wrote I'm making a class and the parameters I'm feeding the class is getting quite large. I'm up to 8 now. Is there any rules of thumb for classes with a lot of parameters? There are no rules as such. Some of the Tkinter classes for excample take a

Re: [Tutor] class initialization with a lot of parameters

2009-11-09 Thread Dave Angel
C.T. Matsumoto wrote: Hello All, I'm making a class and the parameters I'm feeding the class is getting quite large. I'm up to 8 now. Is there any rules of thumb for classes with a lot of parameters? I was thinking to put the parameters into a tuple and then in the __init__ of the class,

Re: [Tutor] class Knights vs class Knights(object)

2009-11-07 Thread Patrick Sabin
Wayne Werner wrote: and my question is what is the difference between the two? Is there a difference other than one is an object the other is an instance? I googled python object vs. instance and didn't find anything terribly useful. Yes there is a difference. One class inherits from

Re: [Tutor] class attribute to initiate more classes

2009-10-31 Thread Dave Angel
Vincent Davis wrote: I have a program that generates many instances of a class with an attribute self.x = random.gauss(10, 2). So each instance has a different value for self.x. This is what I want. Now I want to make a class that starts my program and sets the attributes. class people: def

Re: [Tutor] class attribute to initiate more classes

2009-10-31 Thread Kent Johnson
On Sat, Oct 31, 2009 at 1:01 AM, Vincent Davis vinc...@vincentdavis.net wrote: I have a program that generates many instances of a class with an attribute self.x = random.gauss(10, 2). So each instance has a different value for self.x. This is what I want. Now I want to make a class that starts

Re: [Tutor] class attribute to initiate more classes

2009-10-31 Thread Vincent Davis
DaveA posted import random, functools class Person: def __init__(self, size): self.size = size def __str__(self): return Person of size %s % self.size class MakePeople: def __init__(self, random_func): self.random_func = random_func def

Re: [Tutor] class attribute to initiate more classes

2009-10-31 Thread Dave Angel
(You top-posted, which confuses the sequence of message text. So I clipped it off and posted my message at the bottom, which is the convention on this newsgroup) Vincent Davis wrote: DaveA posted import random, functools class Person: def __init__(self, size): self.size = size

Re: [Tutor] class attribute to initiate more classes

2009-10-31 Thread Vincent Davis
Vincent Davis wrote: DaveA posted import random, functools class Person: def __init__(self, size): self.size = size def __str__(self): return Person of size %s % self.size class MakePeople: def __init__(self, random_func): self.random_func =

Re: [Tutor] class attribute to initiate more classes

2009-10-30 Thread Michiel Overtoom
On 31 Oct 2009, at 06:01 , Vincent Davis wrote: I hope this makes sense, I am sure there is a term for what I am trying to do but I don't know it. What a strange program. But at least it compiles: import random class people: def __init__(self, size): self.size = size class

Re: [Tutor] class with objects

2009-10-11 Thread Wayne
On Sun, Oct 11, 2009 at 2:42 PM, shellc...@juno.com shellc...@juno.comwrote: I want to display the ship default value for zero and display the ship's initial fuel level. Also have a method called status that displays an object's name and fuel values. I want to have several Ship objects and

Re: [Tutor] class with objects

2009-10-11 Thread Alan Gauld
shellc...@juno.com wrote I want to display the ship default value for zero and display the ship's initial fuel level. Also have a method called status that displays an object's name and fuel values. So far so good. I want to have several Ship objects and call their status() methods to

Re: [Tutor] class design

2009-06-06 Thread Kent Johnson
On Sat, Jun 6, 2009 at 5:04 AM, Norman Khinenor...@khine.net wrote: Hello, I would like help to design the following: http://paste.lisp.org/display/81448 Product.get_days() may have a bug, it only returns the first container it finds. You probably don't want the view code in the same class

Re: [Tutor] class design

2009-06-06 Thread Norman Khine
Thanks for the reply. I am using the iTools python library from http://hforge.org (http://git.hforge.org/) and the data is stored as XML files. On Sat, Jun 6, 2009 at 1:02 PM, Kent Johnsonken...@tds.net wrote: On Sat, Jun 6, 2009 at 5:04 AM, Norman Khinenor...@khine.net wrote: Hello, I would

Re: [Tutor] class design

2009-06-06 Thread Alan Gauld
Norman Khine nor...@khine.net wrote In my application I have 3 folders each containing images, something like: $ tree -L 3 /database/companies/company/ |-- product | |-- itinerary | | |-- img1.gif | | |-- img1.gif.metadata | | |-- day1 | | | |-- img2.gif | | | `--

Re: [Tutor] class design

2009-06-06 Thread Norman Khine
Hi On Sat, Jun 6, 2009 at 2:38 PM, Alan Gauldalan.ga...@btinternet.com wrote: Norman Khine nor...@khine.net wrote In my application I have 3 folders each containing images, something like: $ tree -L 3 /database/companies/company/ |-- product |   |-- itinerary |   |   |-- img1.gif |   |  

Re: [Tutor] class design

2009-06-06 Thread Kent Johnson
On Sat, Jun 6, 2009 at 8:26 AM, Norman Khinenor...@khine.net wrote: You probably don't want the view code in the same class with the data. It's generally a good idea to separate the model - the representation of data - from the view - the display of the data. In iTools, each class has a

Re: [Tutor] class design

2009-06-06 Thread Norman Khine
http://docs.hforge.org/itools/web.html although this is for the newer version, in my case i am maintaining an older version. On Sat, Jun 6, 2009 at 3:24 PM, Kent Johnsonken...@tds.net wrote: On Sat, Jun 6, 2009 at 8:26 AM, Norman Khinenor...@khine.net wrote: You probably don't want the view

Re: [Tutor] class design

2009-06-06 Thread Kent Johnson
On Sat, Jun 6, 2009 at 10:43 AM, Norman Khinenor...@khine.net wrote: http://docs.hforge.org/itools/web.html although this is for the newer version, in my case i am maintaining an older version. From that page it seems that itools does as I suggest. They claim to follow the Model-View-Controller

Re: [Tutor] class design

2009-06-06 Thread ALAN GAULD
In simple terms I was trying to create a 'folder with a view' which displays all the data it contains on one page, rather than having to view each node individually. In that case I'd probably create a FolderView class with a show or display method. If you want to do something with the

Re: [Tutor] Class Tips

2009-05-31 Thread David
ALAN GAULD wrote: but I get an error here; def main(): frate = FertRate(get_inputs()) File ./fert_class.py, line 15, in main frate = FertRate(get_inputs()) TypeError: __init__() takes exactly 5 arguments (2 given) Sorry my mistake. Because get_inputs() returns a tuple you

Re: [Tutor] Class Tips

2009-05-31 Thread David
W W wrote: One thing that's probably not in the scope of the program but really usually a good idea is error checking. i.e. this line: rate = float(raw_input(Enter rate i.e. (0.5) : )) could be converted to something like: try: rate = float(raw_input(Enter rate...)) except ValueError:

Re: [Tutor] Class Tips

2009-05-31 Thread Alan Gauld
David da...@abbottdavid.com wrote OK, this is what I came up with, how else could I do it so as not to use sys.exit() ? You don;t need the exit(), The program will just drop off the end silently without it. Thre are several other redundant bits you could just miss out: class FertRate:

Re: [Tutor] Class Tips

2009-05-30 Thread Alan Gauld
David da...@abbottdavid.com wrote I took this program that determines a fertilizer application rate; ... And converted it to class/object to learn how they work. Just looking for some pointers, if I did it correctly etc. For such a small program its hard to see what else you could have

Re: [Tutor] Class Tips

2009-05-30 Thread David
Alan Gauld wrote: David da...@abbottdavid.com wrote I took this program that determines a fertilizer application rate; ... And converted it to class/object to learn how they work. Just looking for some pointers, if I did it correctly etc. For such a small program its hard to see what else

Re: [Tutor] Class Tips

2009-05-30 Thread W W
On Sat, May 30, 2009 at 8:20 PM, David da...@abbottdavid.com wrote: Alan Gauld wrote: David da...@abbottdavid.com wrote I took this program that determines a fertilizer application rate; ... And converted it to class/object to learn how they work. Just looking for some pointers, if I did

Re: [Tutor] Class instance understanding = None

2009-02-27 Thread Andre Engels
On Fri, Feb 27, 2009 at 6:06 AM, David da...@abbottdavid.com wrote: Hi Everyone, I go through the archived [Tutor] mail list to find programs others have tried to do. I found one that would keep track of a petty cash fund. please point out my misunderstanding. Here is what I started with;

Re: [Tutor] Class instance understanding = None

2009-02-27 Thread David
Thank you spir and Andre for the explanation. You are very good teachers. I can now continue. I am sure I will be back. Next I am going to set up a menu to enter amounts and also a way to store the resulting balance. Is cPickle a good way to do this? -david -- Powered by Gentoo GNU/LINUX

Re: [Tutor] Class definition...

2009-02-27 Thread Spencer Parker
Your tutorial is awesome...thanks again... The biggest confusion I have just had is the self.balance kind of thing. I need to just remember how it is treating each individual statement is all. Remember how everything is basically an object...just wrapping my brain around it for the most part.

Re: [Tutor] Class instance understanding = None

2009-02-27 Thread David
Andre Engels wrote: The more preferable method is to leave the class alone, and call getbalance by hand: data = float('100.00') a = Account(data) p = a.getbalance() print 'balance = ', p remove_data = float('50.00') a.withdraw(remove_data) w = a.getbalance() print withdraw = , w add_data =

Re: [Tutor] Class instance understanding = None

2009-02-27 Thread David
David wrote: but when I change it to; start_total() start = start_total() a = Account(start) here is the error; Enter Amount: 100 Traceback (most recent call last): File ./py_pettycash.py, line 77, in module menu() File ./py_pettycash.py, line 53, in menu a.deposit(cash) File

Re: [Tutor] Class definition...

2009-02-27 Thread wesley chun
I am looking for a good tutorial to walk through that really explains class definition. I assume from that you have been through the basic tutors like mine? : OK, I explain self in my OOP tutor topic ( a sub heading under Using Classes), but again if thats not sufficient then you

Re: [Tutor] Class definition...

2009-02-26 Thread Alan Gauld
Spencer Parker inthefri...@gmail.com wrote I am looking for a good tutorial to walk through that really explains class definition. This has been one sticking point that always messes me up I assume from that you have been through the basic tutors like mine? Have you tried the deeper

Re: [Tutor] Class instance understanding = None

2009-02-26 Thread spir
Le Fri, 27 Feb 2009 00:06:59 -0500, David da...@abbottdavid.com s'exprima ainsi: Hi Everyone, I go through the archived [Tutor] mail list to find programs others have tried to do. I found one that would keep track of a petty cash fund. please point out my misunderstanding. Here is what I

Re: [Tutor] Class instance understanding = None

2009-02-26 Thread spir
Le Fri, 27 Feb 2009 00:06:59 -0500, David da...@abbottdavid.com s'exprima ainsi: Hi Everyone, I go through the archived [Tutor] mail list to find programs others have tried to do. I found one that would keep track of a petty cash fund. please point out my misunderstanding. Here is what I

Re: [Tutor] class arguments?

2009-01-23 Thread spir
Le Thu, 22 Jan 2009 23:29:59 -, Alan Gauld alan.ga...@btinternet.com a écrit : Alan Gauld alan.ga...@btinternet.com wrote is there a way to give arguments to a class definition? I see that Kent interpreted your question differently to me. If you do mean that you want to

Re: [Tutor] class arguments?

2009-01-23 Thread Kent Johnson
On Fri, Jan 23, 2009 at 6:04 AM, spir denis.s...@free.fr wrote: Thank you Alan and sorry for not having been clear enough. The point actually was class (definition) attributes. I thought at e.g. Guido's views that lists were for homogeneous sequences as opposed to tuples rather like records.

Re: [Tutor] class arguments?

2009-01-23 Thread Kent Johnson
Forwarding to the list with my reply... On Fri, Jan 23, 2009 at 1:35 PM, spir denis.s...@free.fr wrote: Le Fri, 23 Jan 2009 06:45:04 -0500, Kent Johnson ken...@tds.net a écrit : On Fri, Jan 23, 2009 at 6:04 AM, spir denis.s...@free.fr wrote: Thank you Alan and sorry for not having been

Re: [Tutor] class design - base classes with optional properties?

2009-01-22 Thread Kent Johnson
On Thu, Jan 22, 2009 at 3:04 PM, Marcus Goldfish magoldf...@gmail.com wrote: I'm trying to design a base class for a hierarchy. The properties I want to specify for the base class depend on the values of other properties of the base class. For instance, in this toy example of a base

Re: [Tutor] class arguments?

2009-01-22 Thread Alan Gauld
spir denis.s...@free.fr wrote is there a way to give arguments to a class definition? Eg class MonoList(list, typ, number): item_type = typ item_number = number Yes thats what the __init__ method is for. class MonoList: def __init__(self, lst, typ, num): self.item_type = typ

Re: [Tutor] class arguments?

2009-01-22 Thread Kent Johnson
On Thu, Jan 22, 2009 at 5:18 PM, Kent Johnson ken...@tds.net wrote: On Thu, Jan 22, 2009 at 4:51 PM, spir denis.s...@free.fr wrote: Hello, is there a way to give arguments to a class definition? Eg class MonoList(list, typ, number): item_type = typ item_number = number Use

Re: [Tutor] class design - base classes with optional properties?

2009-01-22 Thread Alan Gauld
Marcus Goldfish magoldf...@gmail.com wrote I'm trying to design a base class for a hierarchy. The properties I want to specify for the base class depend on the values of other properties of the base class. Don't worry so much about the properties, the important thing to focus on in your

Re: [Tutor] class arguments?

2009-01-22 Thread Alan Gauld
Alan Gauld alan.ga...@btinternet.com wrote is there a way to give arguments to a class definition? I see that Kent interpreted your question differently to me. If you do mean that you want to dynamically define class attributes rather than instance attributes then __init__() won't work.

Re: [Tutor] class design - base classes with optional properties?

2009-01-22 Thread Kent Johnson
On Thu, Jan 22, 2009 at 6:24 PM, Alan Gauld alan.ga...@btinternet.com wrote: Marcus Goldfish magoldf...@gmail.com wrote I'm trying to design a base class for a hierarchy. The properties I want to specify for the base class depend on the values of other properties of the base class. Don't

Re: [Tutor] Class Extend Help

2008-12-20 Thread Richard Lovely
There are three ways as I see it: using __getattr__, using a new init, or using a property decorator. The last two are probably the most pythonic, but I'm not familiar with decorators, so here's how I'd do the second of the three: try: from google.appengine.api.urlfetch import fetch except:

Re: [Tutor] Class Extend Help

2008-12-20 Thread Martin Walsh
Omer wrote: Hey. I'm trying to do something I think is basic and am failing. The goal is: [mimicking the google urlopen syntax] try: from google.appengine.api.urlfetch import fetch except: from urllib import urlopen as fetch How do I add this fetch the property of

Re: [Tutor] class/type methods/functions

2008-10-30 Thread bob gailer
spir wrote: Hello, New to the list. I'm a self-taught, amateur programmer. Also, non-native english speaker -- so, don't be surprised with weird expression. Q: Is there a way to write /type/ (class) functions, meaning methods not bound to an instance, in python? Take a look at the

<    1   2   3   4   >