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-------
Date: 04/10/06 12:03:16
Subject: Python-win32 Digest, Vol 37, Issue 10
Send Python-win32 mailing list submissions to
To subscribe or unsubscribe via the World Wide Web, visit
or, via email, send a message with subject or body 'help' to
You can reach the person managing the list at
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)
4. Re: Code help (Aleksandar Cikota) (Bob Gailer)
----------------------------------------------------------------------
Message: 1
Date: Sun, 9 Apr 2006 06:54:32 -0400
Subject: [python-win32] Re: Code help
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
Subject: Re: [python-win32] Code help (Aleksandar Cikota)
Message-ID:
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
Subject: Re: [python-win32] Code help
Content-Type: text/plain; charset=us-ascii
>
>
> 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()
--
Providenza & Boeklheide, Inc.
------------------------------
Message: 4
Date: Sun, 09 Apr 2006 22:36:45 -0700
Subject: Re: [python-win32] Code help (Aleksandar Cikota)
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 mailing list
End of Python-win32 Digest, Vol 37, Issue 10
********************************************
|