"prove"

  • Thread starter Lucas Prado Melo
  • Start date
L

Lucas Prado Melo

Hello,
How could I "prove" to someone that python accepts this syntax using
the documentation (I couldn't find it anywhere):
classname.functionname(objectname)
 
M

Marco Mariani

Lucas said:
How could I "prove" to someone that python accepts this syntax using
the documentation (I couldn't find it anywhere):
classname.functionname(objectname)

TUtorial 9.3.4, method objects

What exactly happens when a method is called? You may have noticed that
x.f() was called without an argument above, even though the function
definition for f specified an argument. What happened to the argument?
Surely Python raises an exception when a function that requires an
argument is called without any -- even if the argument isn't actually
used...

Actually, you may have guessed the answer: the special thing about
methods is that the object is passed as the first argument of the
function. In our example, the call x.f() is exactly equivalent to
MyClass.f(x). In general, calling a method with a list of n arguments is
equivalent to calling the corresponding function with an argument list
that is created by inserting the method's object before the first argument.
 
H

hdante

Hello,
How could I "prove" to someone that python accepts this syntax using
the documentation (I couldn't find it anywhere):
classname.functionname(objectname)

It's in the language reference, section 3.2 "The standard type
hierarchy", subsection "Classes". The relevant paragraphs are those:

Classes
Class objects are created by class definitions (see section 7.7,
``Class definitions''). A class has a namespace implemented by a
dictionary object. Class attribute references are translated to
lookups in this dictionary, e.g., "C.x" is translated to
"C.__dict__["x"]". When the attribute name is not found there, the
attribute search continues in the base classes. The search is depth-
first, left-to-right in the order of occurrence in the base class
list.

When a class attribute reference (for class C, say) would yield a
user-defined function object or an unbound user-defined method object
whose associated class is either C or one of its base classes, it is
transformed into an unbound user-defined method object whose im_class
attribute is C. When it would yield a class method object, it is
transformed into a bound user-defined method object whose im_class and
im_self attributes are both C. When it would yield a static method
object, it is transformed into the object wrapped by the static method
object. See section 3.4.2 for another way in which attributes
retrieved from a class may differ from those actually contained in its
__dict__.

http://docs.python.org/ref/types.html
 
B

Bruno Desthuilliers

Lucas Prado Melo a écrit :
Hello,
How could I "prove" to someone that python accepts this syntax using
the documentation (I couldn't find it anywhere):
classname.functionname(objectname)

Why do you need the documentation ? Just fire up your python shell and
hack a Q&D example:

Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information..... def bar(self):
.... print "in %s bar" % self
....
 
L

Lucas Prado Melo

Why do you need the documentation ? Just fire up your python shell and hack
a Q&D example:
I agree. I said it to this person, but he insisted I should use documentation...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top