Anomaly in creating class methods

2005-11-03 Thread venk
Hi,
 given below is my interaction with the interpreter In one case, i
have created the class method using the "famous idiom"... and in the
other, i have tried to create it outside the class definition... why
isn't the latter working ? (of course, the presence of decorators is a
different issue)
>>> class D:
... def f(cls):
... print cls
...
>>> D.f=classmethod(D.f)
>>> D.f
>
>>> D.f()
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: unbound method f() must be called with D instance as first
argument (got classobj instance instead)
>>> class D:
... def f(cls):
... print cls
... f=classmethod(f)
...
>>> D.f
>
>>> D.f()
__main__.D

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class Variable Access and Assignment

2005-11-03 Thread venk
You see,
 The seen behavior is due to the result of python's name
binding,scoping scheme.
Let me give you an example,
 class A:
 i=0
 def t(self):
 print self.i
 self.i=4
then
a=A()
a.i is 0
a.t()
then,
A.i is 0
a.i is 4

In the function, it first searches for i in its local scope, on not
finding it, accesses the class object's i.
then the next line, is an assignment, which binds (creates a new
variable) in the instance's scope. you can use the buit-in id function
to verify it.

the same thing happens in the case of b.a = b.a + 2  search for b.a
not found, read the value from the enclosing scope (of the class
object) then assign b.a to the local scope, with the value 3.

But, I think your question about the sanity of the behaviour should be
analysed sincerely

if,
k=0
def f():
   print k
   k=k+1
raises UnboundLocalError, then how is it accepted in the former case?
hmmm

maybe, my arguments are hapazard but, i'll get to know when i'm
flamed ;)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT - Re: Microsoft Hatred FAQ

2005-11-03 Thread venk
Hi,
 Though out of the streamline, I find your post to be one of the most
reasonable and well-formed arguments I have read in a long time. Keep
it up. Great work.

Steven D'Aprano wrote:
Real standards, like TCP/IP which is the backbone of the Internet,
aren't
controlled by any one company. Anyone can create a TCP stack. Nobody
but
Microsoft can create a competing version of Windows. TCP/IP became a
standard long before Microsoft even acknowledged it's existence. So did
ASCII, the IBM BIOS, and serial ports, to name just a few. Does the
term
"ISO standard" mean anything to you?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class Variable Access and Assignment

2005-11-03 Thread venk
hey,
 did  u read my reply fully? i too feel that this matter of raising
unbound local error in one case and not raising it in the other must be
analysed...

quoting from the documentation
"If a name binding operation occurs anywhere within a code block, all
uses of the name within the block are treated as references to the
current block. This can lead to errors when a name is used within a
block before it is bound. This rule is subtle. Python lacks
declarations and allows name binding operations to occur anywhere
within a code block. The local variables of a code block can be
determined by scanning the entire text of the block for name binding
operations."

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class Variable Access and Assignment

2005-11-03 Thread venk
Again (blink) quoting from the docs "
For targets which are attribute references, the initial value is
retrieved with a getattr() and the result is assigned with a setattr().
Notice that the two methods do not necessarily refer to the same
variable. When getattr() refers to a class variable, setattr() still
writes to an instance variable. For example:

class A:
x = 3# class variable
a = A()
a.x += 1 # writes a.x as 4 leaving A.x as 3
"

I felt a wee bit clear after going thru the doc... attribute
referencing is not the same as searching the variable in the enclosing
scopes But, i still feel the inconsistency...

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Anomaly in creating class methods

2005-11-03 Thread venk
Cool,
 i got it now... accessing thru attribute reference always
returns a bound or unbound method... so, D.f is an unbound method
whereas i want the "function" of the unbound method... ok, this
example and the nice explanations definitively thought me about
function, bound method (for which the function is just an attribute
accessed by im_func) and unbound method...
  Also, calling classmethod on an unbound method instead of a function
is a strict no... no...
  ok... nice concept...

But, i am at loss when i come to clearly understanding the difference
between new-style classes and classic classes (or should i post it
as new topic?).

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reading internet data to generate random numbers.

2005-11-03 Thread venk
hotbits hotbits hotbits!

http://www.fourmilab.ch/hotbits/

based on quantum mechanics check it out!

-- 
http://mail.python.org/mailman/listinfo/python-list


Diff. between Class types and classic classes

2005-11-08 Thread venk
Hi,
  can some one properly explain the differences between class types and
classic classes? ... Still face problems in identifying what is what.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Diff. between Class types and classic classes

2005-11-11 Thread venk
Dear Colin,
Forgive me for this late reply. Your explanation was of great help to
me. 
Thank you very much. It was crystal clear.

-- 
http://mail.python.org/mailman/listinfo/python-list


Changing fill in tkinter

2006-01-13 Thread venk
Hi,
 I would like to know how to change the fill of things we put in a
tkinter's canvas. for example, if i create a rectangle and i would want
to change the fill of the rectangle once it is clicked... can we do
that?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing fill in tkinter

2006-01-13 Thread venk
yes, it was a stupid mistake from my part in not pondering over the api
fully. forgive me. anyways, ii was just looking for item configure. (I
was spending all my time searching google rather than reading the api
sincerely. duh...)

-- 
http://mail.python.org/mailman/listinfo/python-list