473,480 Members | 1,777 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

function without brackets ?

If I call a parameterless function without brackets at the end,
the function is not performed, but ...
I don't get an error message ???

Is this normal behavior ?

thanks,
Stef Mientki
Jan 3 '07 #1
5 14020
Stef Mientki <S.**************@mailbox.kun.nltyped
If I call a parameterless function without brackets at the end,
the function is not performed, but ...
If you omit the brackets, you don't actually call the function. Instead
you get a reference to the function object.

Consider this example:

cwd = os.getcwd()
# cwd now contains a string, denoting the current working directory
func = os.getcwd
# func now contains a reference to the function os.getcwd
print func == os.getcwd # prints True
# you can even call it:
cwd_2 = func()
# cwd_2 now also contains a string with the current directory.
print cwd == cwd_2 # prints True, too

--
Freedom is always the freedom of dissenters.
(Rosa Luxemburg)
Jan 3 '07 #2
Stef Mientki <S.**************@mailbox.kun.nlwrote in news:57668
$4**********************@news.speedlinq.nl:
If I call a parameterless function without brackets at the end,
the function is not performed, but ...
I don't get an error message ???

Is this normal behavior ?
Yes, it's normal, but you did not in fact call the function, if you
were using Python. Functions are objects that, for example, can be
passed to other functions. The way to refer to the functions
themselves is to omit the arguments and parentheses. So by simply
stating the name of a function, that's all you've done.

--
rzed
Jan 3 '07 #3
On Wed, 2007-01-03 at 15:37 +0100, Stef Mientki wrote:
If I call a parameterless function without brackets at the end,
the function is not performed, but ...
I don't get an error message ???

Is this normal behavior ?
Yes. If you "call" a function without brackets, it's not a call.

Remember that functions are first class objects that can be passed
around like any other object. Hence, Python needs the distinction
between

x = foo() # Assign the *result* of calling foo to x

and

x = foo # Assign the *function* foo itself to x.

You don't get an error message because a function name without
parentheses is a valid expression that refers to that function.

Hope this helps,

Carsten.
Jan 3 '07 #4

Stef Mientki schrieb:
If I call a parameterless function without brackets at the end,
the function is not performed, but ...
I don't get an error message ???

Is this normal behavior ?
Yes, this is perfectly o.k. because each function is a first class
citizen in Python. The difference between foo() and foo is simply that
foo() is the value returned by the function call on foo and foo is a
function object.

Kay

Jan 3 '07 #5
Hope this helps,
thanks You all guys,
It's perfectly clear to me now !

cheers,
Stef
Jan 3 '07 #6

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

Similar topics

11
9056
by: Kamilche | last post by:
What a debug nightmare! I just spent HOURS running my script through the debugger, sprinkling in log statements, and the like, tracking down my problem. I called a function without the ending...
1
11550
by: Joel Thornton | last post by:
Is it possible to call a user-defined function without prefixing it with 'dbo.' within a SELECT clause somehow? Just curious; it's not a big issue but just a stylistic one for me. Thanks! ...
28
3421
by: OSHIMA | last post by:
Hi, I found the swap() function without a temporary variable. void swap(int *x, int *y){ *x ^= *y; *y ^= *x; *x ^= *y; } So, I wrote the next code that exchange the double.
1
2541
by: Seong-Kook Shin | last post by:
Hi. Just curiocity, Because of pre-ANSI C, it is possible to have a function without specifying return type of a function (which makes the return type 'int', though) and give no 'return'...
6
2251
by: lovecreatesbeauty | last post by:
I ever missed a `return' statement when write a function `int HighDigit(Num)' to get the highest digit of an integer. But even if the `return' statement is ignored the function still can obtain...
0
1062
by: lovecreatesbeauty | last post by:
I ever missed a `return' statement when write a function `int HighDigit(Num)' to get the highest digit of an integer. But even if the `return' statement is ignored the function still can obtain...
2
1646
by: Henry | last post by:
Hi guys, I want to write some global functions which can be called from different asp.net page. In Visual Basic, there is a global module which allow me to do that. In Visual Basic .net, I...
2
3709
by: Rick | last post by:
We have a very large web project, during migration from VS 2003 to VS 2005, I'm getting hundreds of warnings: "Function without an 'As' clause; return type of Object assumed." I know this is not...
0
7046
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6908
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
7048
Oralloy
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,...
0
7088
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...
0
5342
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,...
0
2997
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...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
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 ...
0
183
bsmnconsultancy
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...

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.