Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8923717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:12:45+00:00 2026-06-15T07:12:45+00:00

Just a quick question. I’ve tried Googling this but every time you add class

  • 0

Just a quick question. I’ve tried Googling this but every time you add “class” to a Python search it gives you classes on Python. D:

I’ve found threads like this: How can you dynamically create variables via a while loop?

But I don’t think that’s exactly what I’m looking for since concatenation is also part of the variable.

Here’s my while loop:

def main():
    counter = 1
    while counter <= 3:
        print "Name: ",employee[counter].name
        print "ID Number: ",employee[counter].id_number
        print "Department: ",employee[counter].department
        print "Job Title: ",employee[counter].job_title
        print #LB
        counter = counter + 1

main()  

I have my objects set up as:

employee1 = Employee("Susan Meyers", 47899, "Accounting", "Vice President")
employee2 = Employee("Mark Jones", 39119, "IT", "Programmer")
employee3 = Employee("Joy Rogers", 81774, "Manufacturing", "Engineer")

This is the error I receive:

print "Name: ",employee[counter].name
NameError: global name 'employee' is not defined

Obviously I have a class set up as well, but I don’t think I need to paste that for this. What I want it to do is go through the loop and change the counter from 1 to 2 to 3. That way it’ll loop through all three employees.

Is it possible to do that? I’ve only ever done this with arrays so I’m not 100% sure I’m on the right track.

Any tips would be great. <3

Chelsea

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:12:47+00:00Added an answer on June 15, 2026 at 7:12 am

    I think what you are looking for is a list

    employees = []
    for i in xrange(1,10):
        employees.append(employee("some name %s" % i))
    
    employees[4].name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just a quick question, was trying different ways to accomplish this, but ended with
Just a quick question, I'm getting the idea that you don't. Why is this,
Just a quick question on the iphone technology within this business card reader http://www.youtube.com/watch?v=F8z6pcxdrPo
Just a quick question. For the sake of time we plan on just creating
Just a quick question but is it possible to open a helpProvider? All I
Just a quick question, can anyone tell me why this doesnt work and how
Just a quick question (I hope): When I use File.Move it gives me an
just a quick question. I cannot find anything relating to this since I don't
Just a quick question about the Timer class of Flex 4. I have a
Just a quick question, I seem to do this a lot: $saveBtn.bind(click keypress, function(e)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.