0

I ask the DaniWeb Community for guidance in resolving the following NameError.
I have attached the import (OpenOPC for Python Library Module), but basically my code:

import OpenOPC
opc = OpenOPC.client()

produces this NameError:

>>> import OpenOPC
>>> 
>>> opc = OpenOPC.client()

Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
opc = OpenOPC.client()
File "C:\Python27\lib\site-packages\OpenOPC.py", line 152, in __init__
pythoncom.CoInitialize()
NameError: global name 'pythoncom' is not defined
>>> 

Please help me eliminate this NameError.

2
Contributors
4
Replies
10
Views
4 Years
Discussion Span
Last Post by pleasecompile
Featured Replies
  • 1

    Are you sure you[ have installed pywin32 extension module properly](http://sourceforge.net/projects/pywin32/files/)? Error is little strange, though, because if you have problem in the installation of the module, you should get erroor from the import statement allready. Or then the import statement is missing completely. You could try to reinstall pywin32. Read More

0

Thank you for your help. Please excuse my rookieness, but I think it is defined in the import OpenOPC that I imported. I tried attaching the OpenOPC module as a text file to original post but I don't see a link here to it. Here is a partial paste of the OpenOPC module written by author of the module:

      pythoncom.CoInitialize()

  if opc_server == None:
     # Initial connect using environment vars
     if self.opc_server == None:
        if os.environ.has_key('OPC_SERVER'):
           opc_server = os.environ['OPC_SERVER']
        else:
           opc_server = OPC_SERVER
     # Reconnect using previous server name
     else:
        opc_server = self.opc_server
        opc_host = self.opc_host

  opc_server_list = opc_server.split(';')
  connected = False

  for s in opc_server_list:
0

Thanks for resolving this post, pyTony. I did not have installed pywin32. When I install pywin32-217.win32-py2.7.exe it prompts post-install script error:

close failed in file object destructor:
sys.excepthook is missing
lost sys.stderr

My Win7 is 64bit, so later I will try 64bit versions of phython and pywin to see if noticeable performance gain and no more post-install script error.

Thanks again.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.