some questions....

eugene kim eugene1977 at hotmail.com
Tue Nov 26 03:40:33 EST 2002


#!/usr/local/bin/python

wow.. i thought python is easy to learn..
but there are lot's of corks..
namespace, scoping rule, exec, eval..
all confuses me..

first.. about exec
class simple:
    def __init__(self,value):
        self.value = value
        if value == 4 :
            print c ## <--- ok
            print C ## <--- error

    def __repr__(self):
        return str(self.value)
        
if __name__ == '__main__':
    a = 3;
    b = 4;
    c = simple(a)
    d = simple(b)
    print c
    print d

    exec "C = simple(a)"
    print C



another question about exec
aList = ['a', 'b']
for aString in aList:
    aString = myClass(aString)  ## <--error
    exec "aString = myClass(aString)" ## <-- ok


what does eval(aString) do?
a = 3
b = a

print eval("b") ## <--- arn't these same?
print b

thank you for attention



More information about the Python-list mailing list