funcs without () like print

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • iwl

    #1

    funcs without () like print

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

  • Fredrik Lundh

    #2
    Re: funcs without () like print

    "iwl" <Ingo.Wolf@gmx. dewrote:
    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>



    Comment

    • Georg Brandl

      #3
      Re: funcs without () like print

      iwl wrote:
      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

      Comment

      • Paddy

        #4
        Re: funcs without () like print


        iwl wrote:
        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.

        Comment

        • Scott David Daniels

          #5
          Re: funcs without () like print

          iwl wrote:
          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
          scott.daniels@a cm.org

          Comment

          Working...