Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion Creating alot of class instances?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
kk  
View profile  
 More options Jul 5, 2:59 pm
Newsgroups: comp.lang.python
From: kk <maymunbe...@gmail.com>
Date: Sun, 5 Jul 2009 11:59:01 -0700 (PDT)
Local: Sun, Jul 5 2009 2:59 pm
Subject: Creating alot of class instances?
Hi

I am new to Python classes and trying to figure out this particular
issue here. I will need to create instances of a class. But at the
moment I do not know how many instances I will end up having, in every
case it might be different. Most of the documents I read makes this
simpl class-student analogy to explain python classes which is fine.
But in those examples the number and the names of the instances were
known and limited.

I will be querying some data and create class instances based on the
data I gather. But the problem as I mentioned is that I do not know
the names and the number of the end class instances. They will be
based on the content of the data. So how can I create class instances
within a loop and when the loop is done how can I figure out the list
of instances via class membership?  I can track the names by
introducing another list but I want to understand the class side of
things.

The solution might be dead simple but I just cannot figure out at the
moment.

For example this is what I need in the simplest form

class myclass():
 def __init__(self,name):
 self.name=name

for count,data in enumerate(some list):
  instance_count=myclass()
  instance_count.name=data

print instances

thanks


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google