Modules for Python

Steve Holden sholden at holdenweb.com
Thu Oct 25 13:20:06 CEST 2001


"Lukasz Pawelczyk" <pawelczyk at lucent.com> wrote in ...
> Hello,
>
> Could anyone tell me where I can find the modules for Python?
> Especially, I am looking for any module to read MS Excel files
> in Python.
>
What you need, if you are using the Windows platform, is Mark Hammond's
"win32all" extensions. You can find them on ActiveState's web site
(www.activestate.com). I usually find the most convenient way to get them is
to install their ActivePython distribution - just don't try to re-distribute
it, their license is a little different.

Here's an example that runs under the Windows scripting host:

#app=WScript.Application
#app._print_details_() # Use this to see what Python knows about a COM
object.

g_index = 1
# A procedure, using a global.
def Show(desc, value = None):
 global g_index # Need global for g_index, as I locally assign.
 # No global needed to "xl" object, as only referenced.
 # Also note "xl" is assigned later in the script - ie, Python is very late
bound.
 xl.Cells(g_index, 1).Value = desc
 if value: xl.Cells(g_index, 2).Value = value
 g_index = g_index + 1

xl = WScript.CreateObject("Excel.Application")
import sys

xl.Visible = 1
#xl.Workbooks().Add() # Excel versions before 98
xl.Workbooks.Add()

# Show the WScript properties.
Show("Application Friendly Name", WScript.Name)
Show("Application Version", WScript.Version)
Show("Application Context: Fully Qualified Name", WScript.FullName)
Show("Application Context: Path Only", WScript.Path)
Show("State of Interactive Mode", WScript.Interactive)

Show("All script arguments:")
args = WScript.Arguments

for i in xrange(0,args.Count()):
 Show("Arg %d" % i, args(i))

regards
 Steve
--
www.holdenweb.com






More information about the Python-list mailing list