[python-win32] Problem with simple example

Dahlstrom, Roger rdahlstrom at directedge.com
Tue Jul 29 15:47:00 CEST 2008


I copied and pasted your code (except for removing the line break in your line 2) and it worked fine for me.
 
import win32com.client
o = win32com.client.Dispatch("Excel.Application")
o.Visible = 1
o.Workbooks.Add()
o.Cells(1,1).Value = "Hello"
 
This produced a visible Excel window, with Book1 visible and active, with the word "Hello" in row 1 column A.
 
 


________________________________

From: python-win32-bounces at python.org [mailto:python-win32-bounces at python.org] On Behalf Of Murr Von Kater
Sent: Tuesday, July 29, 2008 9:35 AM
To: python-win32 at python.org
Subject: [python-win32] Problem with simple example


Hi all!

I'm beginer in python-win32 and i try a simple example which is described in "Python for Win32 Extensions Help":

import win32com.client
o = win32com.client.Dispatch(" 
Excel.Application")
o.Visible = 1
o.Workbooks.Add() # for office 97 - 95 a bit different!
o.Cells(1,1).Value = "Hello"

But this example falls with traceback:

  File "D:\Python25\pyprojects\pyexample\pyexample.py", line 6, in <module>
    o.Workbooks.Add() # for office 97 - 95 a bit different!
  File "D:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 467, in __getattr__
    if self._olerepr_.mapFuncs.has_key(attr): return self._make_method_(attr)
  File "D:\Python25\Lib\site-packages\win32com\client\dynamic.py", line 295, in _make_method_
    methodCodeList = self._olerepr_.MakeFuncMethod(self._olerepr_.mapFuncs[name], methodName,0)
  File "D:\Python25\Lib\site-packages\win32com\client\build.py", line 297, in MakeFuncMethod
    return self.MakeDispatchFuncMethod(entry, name, bMakeClass)
  File "D:\Python25\Lib\site-packages\win32com\client\build.py", line 318, in MakeDispatchFuncMethod
    s = linePrefix + 'def ' + name + '(self' + BuildCallList(fdesc, names, defNamedOptArg, defNamedNotOptArg, defUnnamedArg, defOutArg) + '):'
  File "D:\Python25\Lib\site-packages\win32com\client\build.py", line 604, in BuildCallList
    argName = MakePublicAttributeName(argName)
  File "D:\Python25\Lib\site-packages\win32com\client\build.py", line 542, in MakePublicAttributeName
    return filter( lambda char: char in valid_identifier_chars, className)
  File "D:\Python25\Lib\site-packages\win32com\client\build.py", line 542, in <lambda>
    return filter( lambda char: char in valid_identifier_chars, className)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 52: ordinal not in range(128)

Is it bug or may be i should set some settings to make it works? I use WinXP and MS Office 2003. Python-win32 has been intalled on my PC with
pywin32-211.win32-py2.5.exe installer.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20080729/ed7a8ed7/attachment.htm>


More information about the python-win32 mailing list