[python-win32] Python-win32 Digest, Vol 37, Issue 10

Aleksandar Cikota alexci at gmx.net
Mon Apr 10 13:18:04 CEST 2006


Thank You! I have also found this:

Always Use Parentheses to Call a Function
You must add parentheses after a function name to call it, whether it takes
arguments or not. That is, use function(), not function. Python functions
are simply objects that have a special operation, a call, that you trigger
with the parentheses. Like all objects, they can also be assigned to
variables, and used indirectly: x = function; x().
In Python training, this seems to occur most often with files. It's common
to see beginners type file.close to close a file, rather than file.close();
because it's legal to reference a function without calling it, the first
version without parenthesis succeeds silently, but does not close the file!


Regards,
Aleksandar
 
 
-------Original Message-------
 
From: python-win32-request at python.org
Date: 04/10/06 12:03:16
To: python-win32 at python.org
Subject: Python-win32 Digest, Vol 37, Issue 10
 
Send Python-win32 mailing list submissions to
  python-win32 at python.org
 
To subscribe or unsubscribe via the World Wide Web, visit
  http://mail.python.org/mailman/listinfo/python-win32
or, via email, send a message with subject or body 'help' to
  python-win32-request at python.org
 
You can reach the person managing the list at
  python-win32-owner at python.org
 
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Python-win32 digest..."
 
 
Today's Topics:
 
   1.  Re: Code help (Roger Upole)
   2. Re: Code help (Aleksandar Cikota) (Justin Ezequiel)
   3. Re: Code help (timr at probo.com)
   4. Re: Code help (Aleksandar Cikota) (Bob Gailer)
 
 
----------------------------------------------------------------------
 
Message: 1
Date: Sun, 9 Apr 2006 06:54:32 -0400
From: "Roger Upole" <rwupole at msn.com>
Subject: [python-win32]  Re: Code help
To: <python-win32 at python.org>
Message-ID: <BAY0-SMTP04AD9A9830BFC06CD79CABA3CF0 at phx.gbl>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
  reply-type=original
 
Aleksandar Cikota wrote:
 
> Python code:
> import win32com.client
> FM = win32com.client.Dispatch('FocusMax.FocusControl')
> FM.Focus
 
Use FM.Focus().
You need the parens to actually call the function.
In Python, FM.Focus just returns a reference to the Focus
method rather than calling the method.
 
    hth
        Roger
 
 
 
------------------------------
 
Message: 2
Date: Mon, 10 Apr 2006 10:13:08 +0800
From: "Justin Ezequiel" <justin.mailinglists at gmail.com>
Subject: Re: [python-win32] Code help (Aleksandar Cikota)
To: python-win32 at python.org
Message-ID:
  <3c6718980604091913y2f35ca35n9d5d7871015e8832 at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
 
FocusMax.FocusControl.Focus starts the auto focus operation and returns when
Focus is complete. This Method has the same effect as if the user clicked
the Focus button on the Focus tab (in FocusMax), but there is no reaction
and  I don't get any error message.
 
Python code:
FM.Focus() # you need the parentheses to call the method
 
in VBScript, the parentheses are not required
 
I sometimes forget the parentheses too when porting VB COM code to Python
 
 
------------------------------
 
Message: 3
Date: Sun, 9 Apr 2006 21:24:54 -0700
From: timr at probo.com
Subject: Re: [python-win32] Code help
To: python-win32 at python.org
Cc: Tim Roberts <timr at probo.com>
Message-ID: <20060409212454.A21611 at probo.com>
Content-Type: text/plain; charset=us-ascii
 
On Sun, 9 Apr 2006 11:41:02, "Aleksandar Cikota" <alexci at gmx.net> wrote:
>
>
> FocusMax.FocusControl.Focus starts the auto focus operation and returns
when
> Focus is complete. This Method has the same effect as if the user clicked
> the Focus button on the Focus tab (in FocusMax), but there is no reaction
> and  I don't get any error message.
>
> It works in Visual Basic Script, I have tryed it, but it doesn't work in
> Python. Why? I'm a beginner in programming and I hope that You can help me

> I have send you a part of the code in Python. It should work, but it doesn
t
>
> Python code:
> import win32com.client
> FM = win32com.client.Dispatch('FocusMax.FocusControl')
> FM.Focus
>
> VBScript (that works):
> Set FM = CreateObject("FocusMax.FocusControl")
> FM.Focus
 
VB allows you to use a shortcut to call functions with no parameters, by
omitting the parentheses.  Python does not.  You need to use:
 
    FM.Focus()
--
- Tim Roberts, timr at probo.com
  Providenza & Boeklheide, Inc.
 
 
------------------------------
 
Message: 4
Date: Sun, 09 Apr 2006 22:36:45 -0700
From: Bob Gailer <bgailer at alum.rpi.edu>
Subject: Re: [python-win32] Code help (Aleksandar Cikota)
To: Justin Ezequiel <justin.mailinglists at gmail.com>
Cc: python-win32 at python.org
Message-ID: <4439EEED.6050401 at alum.rpi.edu>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
 
Justin Ezequiel wrote:
> FocusMax.FocusControl.Focus starts the auto focus operation and returns
when
> Focus is complete. This Method has the same effect as if the user clicked
> the Focus button on the Focus tab (in FocusMax), but there is no reaction
> and  I don't get any error message.
>
> Python code:
> FM.Focus() # you need the parentheses to call the method
>
> in VBScript, the parentheses are not required
>
This also points out a strength of Python over VB: Python lets one refer
to function objects. VB does not. I can for example create a list or
dictionary of functions.
> I sometimes forget the parentheses too when porting VB COM code to Python
> _______________________________________________
> Python-win32 mailing list
> Python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
>
>
 
 
 
------------------------------
 
_______________________________________________
Python-win32 mailing list
Python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32
 
 
End of Python-win32 Digest, Vol 37, Issue 10
********************************************
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20060410/e773bef2/attachment.htm 


More information about the Python-win32 mailing list