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:
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:
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
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
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
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
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
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
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
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
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,
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
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:
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
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
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
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,
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
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
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
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
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
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)
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
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
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
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
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
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
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
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,
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,
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
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
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
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
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
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
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:
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
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
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
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
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
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.
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.
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,
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
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,
(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
___
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
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
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
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.
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
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,
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
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
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
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
(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
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 =
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
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
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
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
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
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
| | | `--
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
| |
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
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
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
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
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
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:
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:
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
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
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
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;
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
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.
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 =
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
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
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
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
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
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
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.
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
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
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
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
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
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.
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
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:
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
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
101 - 200 of 303 matches
Mail list logo