> class Shape(object):
> _count = 0
>
> @classmethod
> def count(cls):
> try:
> cls._count += 1
> except AttributeError:
> cls._count = 1
Ah, clever. This is where I thought I'd need an if/elif
chain, adding a new clause for each subclass. i never thought of
usin
Alan G wrote:
> So If I have a heirarchy of shapes and want a class method that
> only operates on the shape class itself, not on all the
> subclasses then I have to use staticmethod whereas if I want
> the class method to act on shape and each of its sub classes
> I must use a classmethod. The can
- Original Message -
From: "Kent Johnson" <[EMAIL PROTECTED]>
> No, a classmethod is passed the class that it is called on.
> If you have an inheritance tree you don't know this with a
staticmethod.
Aha! Like the OP I was aware of the class/no class distinction
but couldn't see how this
Chuck Allison wrote:
> Hello Chinook,
>
> So is the main motivation for class methods so that you can have the
> class object available? It seems you can have that anyway in a static
> method by just asking.
No, a classmethod is passed the class that it is called on. If you have an
inheritance t
> Sorry for the elementary question: I was wondering if someone could
> explain the difference to me between class and static methods.
Coming
> from other languages, I'm used to static methods, but not "class
> methods". Thanks.
There probably is a deep and subtle difference in Python but to
all
On Tue, 21 Jun 2005 17:58:09 -0400, Chuck Allison wrote
(in article <[EMAIL PROTECTED]>):
> Hello Chinook,
>
> So is the main motivation for class methods so that you can have the
> class object available? It seems you can have that anyway in a static
> method by just asking. I'm sure there's a g
Hello Chinook,
So is the main motivation for class methods so that you can have the
class object available? It seems you can have that anyway in a static
method by just asking. I'm sure there's a good reason for this, but I
haven't yet gotten to the point of mastery where I can see a need for
clas
On Tue, 21 Jun 2005 16:52:09 -0400, Chuck Allison wrote
(in article <[EMAIL PROTECTED]>):
> Sorry for the elementary question: I was wondering if someone could
> explain the difference to me between class and static methods. Coming
> from other languages, I'm used to static methods, but not "class
> Hmmm... you may want to modify the print statements slightly to make
> it more clear which of the two print statements are being displayed.
> As the code stands, it's not clear that 'condition' is ever set to true.
/me slaps himself in the forehead.
After modifying the print statements as s
[EMAIL PROTECTED] wrote:
> for item in function1(args):
> object = class()
> if (function2(item)):
> if (condition):
> object.variable = value
> object.function()
> print object # debug
> print object #debug
>
> The above pseudo code (
On Fri, 3 Jun 2005, [EMAIL PROTECTED] wrote:
> for item in function1(args):
> object = class()
> if (function2(item)):
> if (condition):
> object.variable = value
> object.function()
> print object # debug
> print object #debug
>
> T
* Karl Pflästerer <[EMAIL PROTECTED]> [050506 10:40]:
>Karl
> --
> Please do *not* send copies of replies to me.
> I read the list
My Thanks to both Karl and Rich for help me to
understand this problem. I also appreciate the
documentation reference.
cheers
tim
--
Tim Johnson <[EMAIL
On 6 Mai 2005, [EMAIL PROTECTED] wrote:
>
> The following test script is kind of got me baffled:
>#!/usr/local/bin/python
> class Eval:
> def __getitem__(self,key):
> return eval(key)
>##def test():
>## i = 100
>## b = ["My", "name", "is", "Tim"]
>## test = "this is number %(str(i)
Tim Johnson wrote:
> The following test script is kind of got me baffled:
> #!/usr/local/bin/python
> class Eval:
> def __getitem__(self,key):
> return eval(key)
> ##def test():
> ## i = 100
> ## b = ["My", "name", "is", "Tim"]
> ## test = "this is number %(str(i))s for a test %(' '.
> I am sorta starting to get it. So you could use __init__ to ask for
a
> file name to see if there is one in a folder or not if there is then
> open that file and conitue where that file left off. If its not
there
> create a new file with that name, then start the program? Or do I
have
> that all
On Mar 31, 2005, at 00:44, Kevin wrote:
I am sorta starting to get it. So you could use __init__ to ask for a
file name to see if there is one in a folder or not if there is then
open that file and conitue where that file left off. If its not there
create a new file with that name, then start the p
I am sorta starting to get it. So you could use __init__ to ask for a
file name to see if there is one in a folder or not if there is then
open that file and conitue where that file left off. If its not there
create a new file with that name, then start the program? Or do I have
that all wrong?
Th
> In a class is every def called a method
Strictly speaking only those that have a 'self' parameter(or
equivalent)
The others are "unbound functions" and pretty useless, usually being
the result of programmer errors!...
> and the def __init__(self) is called the constructor method?
Usually.
>
Kevin wrote:
In a class is every def called a method and the def __init__(self) is
called the constructor method? This class stuff is a little confusing.
I don't have a problem writting a def I am still not clear on how to
use a constructor. Is there a site that explains the constructor in
great de
Liam Clarke wrote:
Hi Kent,
So the layering is
GUI - user interaction
Application functionality
CbDao - application-specific database access
DbAccess - generic database access, easy to use
JDBC connection - raw database access, not so easy to use
This sounds a lot like what I'm aiming for in a
Hi Kent,
>So the layering is
>GUI - user interaction
>Application functionality
>CbDao - application-specific database access
>DbAccess - generic database access, easy to use
>JDBC connection - raw database access, not so easy to use
This sounds a lot like what I'm aiming for in a project, the
> Does it make sense to do this:
That depends on what you are trying to do!
If its to make scrambled eggs thewn nope, no sense
whatsoever, but if writing a programme storing an
instance inside another instance is very common
indeed! :-)
> In [2]: class AB:
>...: pass
>...:
> In [3
Luis N wrote:
Does it make sense to do this:
In [2]: class AB:
...: pass
...:
In [3]: a = AB()
In [4]: a
Out[4]: <__main__.AB instance at 0x8428bec>
In [5]: class BC:
...: def __init__(self, foo):
...: self.foo = foo
In [6]: b = BC(a)
In [7]: b.foo
Out[7]: <__main__.AB i
class Reader:
def __init__(self, filePath=""):
self.dataA=SchemaA()
self.dataB=SchemaB()
...
class SchemaA():
class SchemaB():
You probaly should put the Schema definitions before the Reader
definition. Otherwise what you suggest is absolutely the norm
for O
rning lots! Thanks
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of Alan Gauld
> Sent: 12 January 2005 20:13
> To: Alan Gauld; Barnaby Scott; 'Tutor'
> Subject: Re: [Tutor] class instance with identity crisis
>
&
Whoops, I forgot to do an assignment...
> So try
>
> def dry(self): return Prune()
>
> > class Prune:
> > def __str__(self):
> > return 'prune'
> >
> > weapon = Damson()
> > weapon.dry()
weapon = weapon.dry()
> > print weapon
>
> Should work as expected...
Alan G
__
> My opinion is : this is a very dangerous and "stupid" thing to do
!!!
No its quite common. Its why C++ for example allows you to write
your own type convcersion functions! One area where I've used this
is to convert faults to orders in a service management application.
Its fairly common for a c
> class Damson:
> def __str__(self):
> return 'damson'
>
> def dry(self):
> self = Prune()
You'll neeed to return it for the outside world to use it...
So try
def dry(self): return Prune()
> class Prune:
> def __str__(self):
> return 'prune'
>
> weapon
On Wed, 12 Jan 2005, Barnaby Scott wrote:
> I was wondering how you can get an instance of a class to change itself
> into something else (given certain circumstances), but doing so from
> within a method. So:
>
> class Damson:
> def __str__(self):
> return 'damson'
>
> def dry(s
Barnaby Scott wrote:
class Damson:
def __str__(self):
return 'damson'
def dry(self):
self = Prune()
class Prune:
def __str__(self):
return 'prune'
weapon = Damson()
weapon.dry()
print weapon
[...]
but something in me suggests it should produce
prune
After all, 's
On Wednesday 12 January 2005 12:10, Kent Johnson wrote:
> A couple of ideas:
>
> You could have dry() return the new weapon:
>def dry(self):
> return Prune()
>
> then the client code would be
> weapon = weapon.dry()
>
>
> You could have the weapon encapsulate another object and delegate to
A couple of ideas:
You could have dry() return the new weapon:
def dry(self):
return Prune()
then the client code would be
weapon = weapon.dry()
You could have the weapon encapsulate another object and delegate to it.
Finally, you actually can change the class of an object just by assigning t
My opinion is : this is a very dangerous and "stupid" thing to do !!!
Try to imagine the complexity of your program for someone who is trying
to understand how your code is working if an object suddenly change its
own type !!! Clearly, if you want to change the type of an object, you
want a con
Alan Gauld said unto the world upon 2004-12-20 15:51:
I hope that short history of OOP clarifies rather than
confuses! :-)
Alan G.
Thanks for that Alan. Seems to clarify thing to me ;-)
Best,
Brian vdB
___
Tutor maillist - [EMAIL PROTECTED]
http://mail
> > Its another reason why you should never refer to
> > an object or method *calling* another method
> > (as Pilgrim does). Rather think of the method
> > sending a *message* to the self object which
> > invokes the appropriate method.
> The contrast you suggest between calling a method and sendi
Alan Gauld said unto the world upon 2004-12-20 09:27:
Its another reason why you should never refer to
an object or method *calling* another method
(as Pilgrim does). Rather think of the method
sending a *message* to the self object which
invokes the appropriate method. This decoupling
of message
You've got it right Brian. It is this ability to change the way
*existing* code works that makes OOP more than a neat way to
package data and functions. This is polymorphism at its
most powerful.
Its why in a C++/Java world the convention is to write
hook methods that are called by the public meth
Kent Johnson said unto the world upon 2004-12-18 08:53:
Yup, that's right!
Attribute access (the dot operator '.') is an operation that happens at
runtime, and each attribute access stands alone. Every attribute access
goes through the same search path, starting with self, then the class
(type)
Yup, that's right!
Attribute access (the dot operator '.') is an operation that happens at runtime, and each attribute
access stands alone. Every attribute access goes through the same search path, starting with self,
then the class (type) of self, finally the base classes. So, in your example, s
301 - 339 of 339 matches
Mail list logo