Re: Accessing class variable at class creation time

2005-09-26 Thread Dave Hansen
On 23 Sep 2005 14:01:21 -0700, "Carlos" <[EMAIL PROTECTED]> wrote: >Hi! > >class A: > X = 2 > def F(): >print A.X > F() > >The above fails because the name A is not >yet at global scope when the reference A.X Maybe I'm missing something. Python 2.4.1#65 under Win32 Idle 1.1.1 gives me the

Re: Accessing class variable at class creation time

2005-09-25 Thread Carlos
Thank you all! After all, I found at least three more or less convenient alternatives: 1) Pass X as default parameter to F. 2) Set globals() from inside A, something like globals()['A_locals'] = locals() or globals()['A_X'] = X. Then access A_locals or A_X from F. 3) Use sys._getframe(1) or sys._

Re: Accessing class variable at class creation time

2005-09-24 Thread Benji York
Jan-Ole Esleben wrote: > That doesn't really give him a way of using the class variable inside a > method. Oh! I must have misunderstood the question. I'd like to know more about why the OP wants to do this; a small example would help narrow down the possibilities. -- Benji York -- http://ma

Re: Accessing class variable at class creation time

2005-09-24 Thread Jan-Ole Esleben
That doesn't really give him a way of using the class variable inside a method. Ole 2005/9/24, Benji York <[EMAIL PROTECTED]>: > Carlos wrote: > > Hi! > > > > class A: > > X = 2 > > def F(): > > print A.X > > F() > > > > The above fails because the name A is not > > yet at global scope

Re: Accessing class variable at class creation time

2005-09-23 Thread Benji York
Carlos wrote: > Hi! > > class A: > X = 2 > def F(): > print A.X > F() > > The above fails because the name A is not > yet at global scope when the reference A.X > is reached. Is there any way to refer to A.X > without making explicit use of the name 'A'? How about this: >>> class A:

Re: Accessing class variable at class creation time

2005-09-23 Thread Simon Percivall
It might be that I'm complicating something easy here, but I immediately thought of import sys class A: X = 2 def F(): f = sys._getframe().f_back print f.f_locals["X"] F() -- http://mail.python.org/mailman/listinfo/python-list

Re: Accessing class variable at class creation time

2005-09-23 Thread Jan-Ole Esleben
You could use self.__class__.X HTH, Ole 23 Sep 2005 14:01:21 -0700, Carlos <[EMAIL PROTECTED]>: > Hi! > > class A: > X = 2 > def F(): > print A.X > F() > > The above fails because the name A is not > yet at global scope when the reference A.X > is reached. Is there any way to refer to

Accessing class variable at class creation time

2005-09-23 Thread Carlos
Hi! class A: X = 2 def F(): print A.X F() The above fails because the name A is not yet at global scope when the reference A.X is reached. Is there any way to refer to A.X without making explicit use of the name 'A'? Admittedly the code looks pretty unusual, but I'm defining configurati