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.

where is the pythoncom defined?

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:

Are you sure you have installed pywin32 extension module properly? 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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.