some questions....

Dennis Lee Bieber wlfraed at ix.netcom.com
Tue Nov 26 01:28:39 EST 2002


eugene kim fed this fish to the penguins on Tuesday 26 November 2002 
12:40 am:

> #!/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)
                        You just created a "c"
>     d = simple(b)
                        So this instance can find a "c" to print.
                        There is NO "C" in existance at this point in the 
                        program
>     print c
>     print d
> 
>     exec "C = simple(a)"
>     print C
                        NOW you have created a "C"

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

                        Again, my first question is WHY are you 
                        assigning the result to a loop index?

>     exec "aString = myClass(aString)" ## <-- ok

                        And what does myClass actually contain?

-- 
 > ============================================================== <
 >   wlfraed at ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed at dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <




More information about the Python-list mailing list