Go Back   CodingForums.com > :: Server side development > Other server side languages/ issues > Python

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-15-2010, 05:47 PM   PM User | #1
HeelToeHeroe
New to the CF scene

 
Join Date: Nov 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
HeelToeHeroe is an unknown quantity at this point
can't create object instance!?

Hello all,
first post here. I am a programming student learning python (I know some other languages pretty well) and I am baffled by this problem. I normally code in linux, but this program is for windows(don't see anything that makes this matter, but just in case).
I am trying to make an instance of the class Employee. When I try to do so, it says "Unbound Local Error: Local variable 'Employee' referenced before assignment". The thing is, I'm trying to create it, lol. I believe I have the right number of arguments for the __init__ function (self doesn't count when you create an instance, right?) so it shouldn't be looking for a different Employee class. Thanks for the help.
-HeelToe

Code:
import time
import os

global emps

def main():
    startup()
    loopit()
    return

class Employee:
    def __init__(self, ID, namef, namel):
            self.PID =ID
            self.fname = namef
            self.lname = namel
            self.timein = []
            self.timeout = []
            self.clockedin = 0
            
    def show_wk_times():
        print "showing week times for ", self.PID
        
    def show_all_times():
        print "showing all times for ", self.PID

def startup():
    #os.system("cls")
    global emps
    emps = []
    print "starting up!"

def loopit():
    running = 1
    global emps
    #x = Employee(6912, 'Eric', 'Olsen')
    emps.append(Employee(6912, "Eric", "Olsen"))
(code continues)
Code:
if __name__ == '__main__':
	main()

Last edited by HeelToeHeroe; 11-15-2010 at 07:36 PM..
HeelToeHeroe is offline   Reply With Quote
Old 11-16-2010, 02:52 AM   PM User | #2
Samhain13
Regular Coder

 
Samhain13's Avatar
 
Join Date: Aug 2008
Location: Pilipinas
Posts: 165
Thanks: 4
Thanked 18 Times in 18 Posts
Samhain13 is on a distinguished road
Quote:
self doesn't count when you create an instance, right?
Right.

Weird though. I just ran your script with the x = Employee line uncommented and the thing works. (Using Python 2.6 in Ubuntu.)
__________________
I am a Man of Truth. I am a Free Human Person. I am a Peacemaker.
** Independent Multimedia Artist in Pasig **
Samhain13 is offline   Reply With Quote
Old 11-16-2010, 03:46 PM   PM User | #3
HeelToeHeroe
New to the CF scene

 
Join Date: Nov 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
HeelToeHeroe is an unknown quantity at this point
interesting....

Quote:
Originally Posted by Samhain13 View Post
Right.

Weird though. I just ran your script with the x = Employee line uncommented and the thing works. (Using Python 2.6 in Ubuntu.)
I just tried running python 2.6 in Ubuntu on my laptop and got the same error...I'll have to scrutinize this later. Thanks for the help though.
HeelToeHeroe is offline   Reply With Quote
Old 11-16-2010, 08:30 PM   PM User | #4
HeelToeHeroe
New to the CF scene

 
Join Date: Nov 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
HeelToeHeroe is an unknown quantity at this point
my friends found it

Sorry, I didn't give you the whole code, namely the segment causing the error. I had a for loop with incorrect syntax:
Code:
for Employee in emps:
....
I thought the 'Employee' had to be the name of the object contained in the list, but it knows what's in the list so I changed it to 'E' and it works. Even though the for loop was after the constructor, it saw 'Employee' as an unbound variable. Thanks though.
-Heeltoe
HeelToeHeroe is offline   Reply With Quote
Old 11-17-2010, 02:26 PM   PM User | #5
Samhain13
Regular Coder

 
Samhain13's Avatar
 
Join Date: Aug 2008
Location: Pilipinas
Posts: 165
Thanks: 4
Thanked 18 Times in 18 Posts
Samhain13 is on a distinguished road
^ Nice.
__________________
I am a Man of Truth. I am a Free Human Person. I am a Peacemaker.
** Independent Multimedia Artist in Pasig **

Last edited by Samhain13; 11-17-2010 at 02:29 PM..
Samhain13 is offline   Reply With Quote
Reply

Bookmarks

Tags
instance, instantiate, object, unbound

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:02 PM.


Advertisement
Log in to turn off these ads.