funcs without () like print

I

iwl

Hello can I make funktions callable without () like print
at time the interpreter seems to printout the adres when I type the
function without ()
 
F

Fredrik Lundh

iwl said:
Hello can I make funktions callable without ()

no, not really.
like print at time the interpreter seems to printout the adres when I type the
function without ()

the interpreter does repr() on the object (which calls the __repr__ method),
and prints the result.

</F>
 
G

Georg Brandl

iwl said:
Hello can I make funktions callable without () like print
at time the interpreter seems to printout the adres when I type the
function without ()

print is not a function, it's a statement, and as such equivalent to
raise or assert.

Georg
 
P

Paddy

iwl said:
Hello can I make funktions callable without () like print
at time the interpreter seems to printout the adres when I type the
function without ()

Hi iwl,
its one of the python fundamentals when dealing with functions.

function_name without the () refers to the function object, that can be
passed around like any other object.
function_name() with the () calls the object referred to by the
function name, attempting to execute the code within it.

So no. you can't call functions without the (), but python provides an
easy way to know when you are calling a function or not: just look for
the ().

- Paddy.
 
S

Scott David Daniels

iwl said:
Hello can I make funktions callable without () like print
at time the interpreter seems to printout the adres when I type the
function without ()

As everyone else has already told you, print is a statement, not a
function. If you want your source code to use these "self-calling-
functions," you should change your wishes.

If, however, you are talking solely about the interactive prompt and
ease of typing, you might want to check out ipython (find via your
favorite search tool). Its flexibility may well be to your taste.

--Scott David Daniels
(e-mail address removed)
 

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
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top