Here is it:
---
class Human:
def __init__(self, eye_one, eye_two):
self.eye_one = eye_one
self.eye_two = eye_two
class Population:
def __init__(self):
self.house = []
for i in range(0, POPULATION_COUNT):
self.house.append(Human(self.GenerateRandomColour( ),
self.GenerateRandomColour()))
def GenerateRandomColour():
rn.seed()
colour = rn.choice(['C', 'P', 'Z'])
return colour
---
Uppon running it gives this error:
---
Initializing first generation population:
Traceback (most recent call last):
File "population.py", line 38, in ?
earth = Population()
File "population.py", line 26, in __init__
self.house.append(Human(self.GenerateRandomColour( ),
self.GenerateRandomColour()))
TypeError: GenerateRandomColour() takes no arguments (1 given)
---
If I remove GenerateRandomColour from class definition, and put it as a
separate function, everything works fine. I've been staring at this code
for half an hour and can't find what's wrong :(.
Any help greatly appriciated :).
--
_______ Karlo Lozovina - Mosor
| | |.-----.-----. web: http://www.mosor.net || ICQ#: 10667163
| || _ | _ | Parce mihi domine quia Dalmata sum.
|__|_|__||_____|_____| 9 1328
Karlo Lozovina wrote: Here is it:
class Population: def __init__(self): self.house = [] for i in range(0, POPULATION_COUNT): self.house.append(Human(self.GenerateRandomColour( ), self.GenerateRandomColour()))
def GenerateRandomColour(): rn.seed() colour = rn.choice(['C', 'P', 'Z']) return colour ---
Uppon running it gives this error:
--- Initializing first generation population: Traceback (most recent call last): File "population.py", line 38, in ? earth = Population() File "population.py", line 26, in __init__ self.house.append(Human(self.GenerateRandomColour( ), self.GenerateRandomColour())) TypeError: GenerateRandomColour() takes no arguments (1 given) ---
If I remove GenerateRandomColour from class definition, and put it as a separate function, everything works fine. I've been staring at this code for half an hour and can't find what's wrong :(.
Class methods must have at least the 'self' argument. So
def GenerateRandomColour(self):
*do something
Gerard
Karlo Lozovina said unto the world upon 04/01/06 04:19 PM: Here is it:
--- class Human: def __init__(self, eye_one, eye_two): self.eye_one = eye_one self.eye_two = eye_two
class Population: def __init__(self): self.house = [] for i in range(0, POPULATION_COUNT): self.house.append(Human(self.GenerateRandomColour( ), self.GenerateRandomColour()))
def GenerateRandomColour(): rn.seed() colour = rn.choice(['C', 'P', 'Z']) return colour ---
Uppon running it gives this error:
--- Initializing first generation population: Traceback (most recent call last): File "population.py", line 38, in ? earth = Population() File "population.py", line 26, in __init__ self.house.append(Human(self.GenerateRandomColour( ), self.GenerateRandomColour())) TypeError: GenerateRandomColour() takes no arguments (1 given) ---
If I remove GenerateRandomColour from class definition, and put it as a separate function, everything works fine. I've been staring at this code for half an hour and can't find what's wrong :(.
You left out self in your GenerateRandomColour method definition.
It should be:
def GenerateRandomColour(self):
rn.seed()
colour = rn.choice(['C', 'P', 'Z'])
return colour
HTH,
Brian vdB
"Gerard Flanagan" <gr********@yahoo.co.uk> wrote in
news:11**********************@g49g2000cwa.googlegr oups.com: Class methods must have at least the 'self' argument. So
Arrrrrgh! :)
Thanks guys!
--
_______ Karlo Lozovina - Mosor
| | |.-----.-----. web: http://www.mosor.net || ICQ#: 10667163
| || _ | _ | Parce mihi domine quia Dalmata sum.
|__|_|__||_____|_____|
You've received good answers to your original question. Just a side
issue...
On Wed, 4 Jan 2006 22:19:27 +0000 (UTC) in comp.lang.python, Karlo
Lozovina <_karlo_@_mosor.net_> wrote:
[...] def GenerateRandomColour(): rn.seed() colour = rn.choice(['C', 'P', 'Z']) return colour
I'm not sure what rn is, but it looks like a standard library
random.Random object. If so, I don't think you want to seed your PRNG
each time you use it -- your numbers might be much less random that
way. If it is the standard library object, the PRNG is seeded when
the module is first imported, so you may not need to seed it at all.
Regards,
-=Dave
--
Change is inevitable, progress is not.
Dave Hansen <id**@hotmail.com> wrote in
news:l8********************************@4ax.com: I'm not sure what rn is, but it looks like a standard library random.Random object. If so, I don't think you want to seed your PRNG each time you use it -- your numbers might be much less random that way. If it is the standard library object, the PRNG is seeded when the module is first imported, so you may not need to seed it at all.
Yes, it is random module. So, what is the preferred way of seeding random
number generator? Just once in a file? Or something else?
I just needed some "random" choices to be made, so I didn't dig much into
random module. Anyway, thanks for pointing this out, appreciated.
--
_______ Karlo Lozovina - Mosor
| | |.-----.-----. web: http://www.mosor.net || ICQ#: 10667163
| || _ | _ | Parce mihi domine quia Dalmata sum.
|__|_|__||_____|_____|
On Thu, 5 Jan 2006 01:14:43 +0000 (UTC) in comp.lang.python, Karlo
Lozovina <_karlo_@_mosor.net_> wrote: Dave Hansen <id**@hotmail.com> wrote in news:l8********************************@4ax.com :
I'm not sure what rn is, but it looks like a standard library random.Random object. If so, I don't think you want to seed your PRNG each time you use it -- your numbers might be much less random that way. If it is the standard library object, the PRNG is seeded when the module is first imported, so you may not need to seed it at all.
Yes, it is random module. So, what is the preferred way of seeding random number generator? Just once in a file? Or something else?
I just needed some "random" choices to be made, so I didn't dig much into random module. Anyway, thanks for pointing this out, appreciated.
From my reading of the library docs, when you import random the PRNG
is seeded (using the current time) for you automatically.
If you call seed without a parameter, it will again use the current
time to seed the generator. But the generator only needs one seed to
generate a random sequence. Re-seeding the generator starts it
proding a new, different sequence. The resulting sequence of numbers
is really the first number in several distinct sequences.
It may be that the sequence of first numbers is "random enough" for
your use. But the call to seed is useless at best, and damaging at
worst.
Unless you want to reproduce the same string of random numbers,
there's really no reason to seed the generator yourself. Consider: rep = random.Random() rep.seed(1234) first = [rep.random() for x in range(10)] second = [rep.random() for x in range(10)] rep.seed(1234) third = [rep.random() for x in range(10)] print first == second
False print first == third
True fourth = [rep.random() for x in range(10)] print second == fourth
True
In your code, I would simply remove the rn.seed() call. Regards,
-=Dave
--
Change is inevitable, progress is not.
Dave Hansen <id**@hotmail.com> wrote in
news:7s********************************@4ax.com: In your code, I would simply remove the rn.seed() call. Regards,
And that's what I'm gonna do :). The random part is not that important to
my application so I wont investigate into further detail... anyway, thank
you.
--
_______ Karlo Lozovina - Mosor
| | |.-----.-----. web: http://www.mosor.net || ICQ#: 10667163
| || _ | _ | Parce mihi domine quia Dalmata sum.
|__|_|__||_____|_____|
For what it's worth, GenerateRandomColour does not access any instance
variables and therefore needn't even be a member of the class
Population. If you wanted it there for encapsulation purposes, consider
making it a staticmethod like so:
@staticmethod()
def GenerateRandomColour():
rn.seed()
colour = rn.choice(['C', 'P', 'Z'])
return colour
Just something to consider...
LL
LordLaraby <Lo*********@gmail.com> wrote: For what it's worth, GenerateRandomColour does not access any instance variables and therefore needn't even be a member of the class Population. If you wanted it there for encapsulation purposes, consider making it a staticmethod like so:
@staticmethod() def GenerateRandomColour(): rn.seed() colour = rn.choice(['C', 'P', 'Z']) return colour
No parentheses on the decorator line, just '@staticmethod'. Otherwise,
fine.
Alex This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: jwayne |
last post by:
I'm trying to implement a navigation bar with multiple a href classes. The
following example works exactly as I want it to, but for Internet Explorer only.
Firefox does not indent each link.
...
|
by: Vic |
last post by:
Dear All,
I found this code snippet on this list (taken from a nice webpage of a
courteous fellow), which I used to filter a form on a combo box. I
wanted to repeat the same code to have an...
|
by: Eric Lilja |
last post by:
Hello, I have two code snippets I want you to look at. My program compiles
without warnings (warning level set to max, gcc 3.4.3) with either snippet
but the latter one causes a segfault at...
|
by: bingfeng |
last post by:
I have some codes generated by perl, in which initialize some huge
struct,such as
PARA TOS_network_spantree_set_0_para_0 = { "vlan", emNUM, NULL, "",
"configuration on a designated vlan",...
|
by: Jason Kid |
last post by:
Hi,
Please tell me what's wrong with the following code.
private bool CheckIt( int iArg, bool fArg)
{
bool fIsGood = false;
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |