On Jun 8, 2:58 am, Hans Nowak <[EMAIL PROTECTED]> wrote:
> Kalibr wrote:
> > On Jun 7, 1:20 pm, Hans Nowak <[EMAIL PROTECTED]> wrote:
> >> Kalibr wrote:
> >>> I've been developing a small script to fiddle with classes, and came
> >>> accross the following problem. Assuming I get some user input ask
Kalibr wrote:
On Jun 7, 1:20 pm, Hans Nowak <[EMAIL PROTECTED]> wrote:
Kalibr wrote:
I've been developing a small script to fiddle with classes, and came
accross the following problem. Assuming I get some user input asking
for a number, how would I spawn 'n' objects from a class?
i.e. I have a
Thanks for all this info.
I'll try all your scripts out.
from what you guys have said, I did the following:
I set up a 'computer class' (I'lm leaving out the mutators)
class computer:
def __init__(self, IP, owner, ph_connections, connections):
assert isIP(IP) == True
self.
Hello,
You can use this as indicated by Hans:
u = [user() for i in xrange(5)]
where "user" is a class or a function returning an object.
u then is a list of "user" objects.
or does it somehow work? how would I address them if they all have the
name 'u'?
You'd access members of the list
On Jun 7, 1:20 pm, Hans Nowak
[user() for i in range(n)]
Kalibr wrote:
or does it somehow work? how would I address them if they all have the
name 'u'?
users = list(User() for i in range(n))
for user in users:
user.do_something()
hth,
Alan Isaac
--
http://mail.python.org/mailma
Kalibr <[EMAIL PROTECTED]> writes:
> what I want to do is have, say 5 users in a game, so I'd have to
> spawn 5 objects. I can't do that because I have'nt hardcoded any
> object names for them.
Python's built-in mapping type 'dict' is a good fit for this.
Given:
* a 'User' class that is initial
On Jun 7, 1:20 pm, Hans Nowak <[EMAIL PROTECTED]> wrote:
> Kalibr wrote:
> > I've been developing a small script to fiddle with classes, and came
> > accross the following problem. Assuming I get some user input asking
> > for a number, how would I spawn 'n' objects from a class?
>
> > i.e. I have
Something like this?
class User:
def __init__(self, name):
self.name = name
def __str__(self):
return self.name
n = 10
users = []
for i in range(n):
users.append(User('user%d' % i))
print users[9]
print users[4]
Cheers,
Paul
On Sat, Jun
Kalibr wrote:
I've been developing a small script to fiddle with classes, and came
accross the following problem. Assuming I get some user input asking
for a number, how would I spawn 'n' objects from a class?
i.e. I have a class class 'user' and I don't know how many of them I
want to spawn.
A