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__
NameError: global name 'pythoncom' is not defined

Please help me eliminate this NameError.

6 Years
Discussion Span
Last Post by pleasecompile

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:


  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']
           opc_server = OPC_SERVER
     # Reconnect using previous server name
        opc_server = self.opc_server
        opc_host = self.opc_host

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

  for s in opc_server_list:

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.