473,473 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

"prove"

Hello,
How could I "prove" to someone that python accepts this syntax using
the documentation (I couldn't find it anywhere):
classname.functionname(objectname)
Jun 27 '08 #1
5 1085
Lucas Prado Melo wrote:
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.
Jun 27 '08 #2
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.
>>class Foo(object):
.... def bar(self):
.... print "in %s bar" % self
....
>>f = Foo()
Foo.bar(f)
in <__main__.Foo object at 0xb7dccd2cbar
>>f.bar()
in <__main__.Foo object at 0xb7dccd2cbar
>>>
Jun 27 '08 #3
"Lucas Prado Melo" <lu*****@dcc.ufba.brwrote:
Hello,
How could I "prove" to someone that python accepts this syntax using
the documentation (I couldn't find it anywhere):
classname.functionname(objectname)

Language reference, mostly section 5.3 Primaries

call ::=
primary "(" [argument_list [","]
| expression genexpr_for] ")"

primary ::=
atom | attributeref
| subscription | slicing | call

attributeref ::=
primary "." identifier

atom ::=
identifier | literal | enclosure
That shows fairly well how the classname.functioname bit works (it is an
attributeref which is a primary which forms the first part of a call),
but you'll have to wade through a fair bit of the grammar to show that
argument_list can be an identifier.
argument_list ::=
positional_arguments ["," keyword_arguments]
["," "*" expression]
["," "**" expression]
| keyword_arguments ["," "*" expression]
["," "**" expression]
| "*" expression ["," "**" expression]
| "**" expression

positional_arguments ::=
expression ("," expression)*

.... and so on ...
Jun 27 '08 #4
On Fri, May 9, 2008 at 5:32 AM, Bruno Desthuilliers
<br********************@websiteburo.invalidwrote :
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...
Jun 27 '08 #5
Thanks for all the answers. I bet I will convince this guy!
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: lkrubner | last post by:
I want to give users the power to edit files from an easy interface, so I create a form and a PHP script called "fileUpdate". It does a reasonable about of error checking and prints out some...
0
by: Andreas Suurkuusk | last post by:
Hi, I just noticed your post in the "C# memory problem: no end for our problem?" thread. In the post you implied that I do not how the garbage collector works and that I mislead people. Since...
15
by: Marc Le Roy | last post by:
Hello, ADA Ravenscar is a restricted subset of the ADA language that has been defined for real-time software development in safety critical applications. Completed with additional restrictions...
145
by: Sidney Cadot | last post by:
Hi all, In a discussion with Tak-Shing Chan the question came up whether the as-if rule can cover I/O functions. Basically, he maintains it can, and I think it doesn't. Consider two...
9
by: Lonnie Princehouse | last post by:
There doesn't seem to be any way to customize the behavior of "is" as can be done for other operators... why not?
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
24
by: Peter Maas | last post by:
The Python FAQ 1.4.5 gives 3 reasons for explicit self (condensed version): 1. Instance variables can be easily distinguished from local variables. 2. A method from a particular class can be...
0
by: David | last post by:
classname.functionname(objectname) Do you mean something like this? class myclass: @staticmethod def myfunction(myobject): pass myobject = None myclass.myfunction(myobject)
24
by: Jeremy J Starcher | last post by:
While reading c.l.j, I've noticed that some people prefer and indeed even recommend the use of "window.alert()" over "alert()". I can't find any technical reason to make this distinction, and...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.