473,545 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ


How could I "prove" to someone that python accepts this syntax using
the documentation (I couldn't find it anywhere):
classname.funct ionname(objectn ame)
Jun 27 '08 #1
5 1090
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.funct ionname(objectn ame)
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

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 :
How could I "prove" to someone that python accepts this syntax using
the documentation (I couldn't find it anywhere):
classname.funct ionname(objectn ame)
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()
in <__main__.Foo object at 0xb7dccd2cbar
in <__main__.Foo object at 0xb7dccd2cbar
Jun 27 '08 #3
"Lucas Prado Melo" <lu*****@dcc.uf ba.brwrote:
How could I "prove" to someone that python accepts this syntax using
the documentation (I couldn't find it anywhere):
classname.funct ionname(objectn ame)

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.funct ioname 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_argu ments ["," keyword_argumen ts]
["," "*" expression]
["," "**" expression]
| keyword_argumen ts ["," "*" expression]
["," "**" expression]
| "*" expression ["," "**" expression]
| "**" expression

positional_argu ments ::=
expression ("," expression)*

.... and so on ...
Jun 27 '08 #4
On Fri, May 9, 2008 at 5:32 AM, Bruno Desthuilliers
<br************ ********@websit eburo.invalidwr ote:
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

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 errors. It uses fileperms() to get the permissions of the file, and it includes that info in any error message. Today I'm getting the following error...
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 the thread is over a month old, I decided to start a new one with my response. Please see my comments inline.
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 like the ones defined in the SPARK profile, it allow to build very deterministic applications that support automatic static code analysis and...
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 programs: /*** a.c ***/
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?
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 paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990....
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 called as baseclass.methodname(self, <argument list>). 3. No need for declarations to disambiguate assignments to local/instance variables.
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)
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 seems to have a (tiny) amount overhead since window itself points to the global object, hence, a circular reference. (From everything I am reading,...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.