Unsubscriptable object when using Exec

Indian write2abdul at gmail.com
Fri Nov 14 13:40:25 EST 2008


Hi Friends

I'm getting the TypeError Unsubscriptable object when using Exec in a class

Here's the example

class Fake(object):
  def __init__(self, reg):
    self._reg = reg

  def OpenKey(self, rootkey, path):
    open_key = self._reg
    path_string='[\'HKLM\']'
    for key in path.split('\\'):
      path_string += '[\'%s\']'%key
    a='d=open_key%s'%path_string
    exec(a)
    return d

When i create a claassobject and call the method Openkey i get the above
error but it works fine in the below example without class

def OpenKey(rootkey, path, reg):
  open_key = reg
  path_string='[\'HKLM\']'
  for key in path.split('\\'):
    path_string += '[\'%s\']'%key
  a='d=open_key%s'%path_string
  print a
  exec(a)
  return d

What am i doing wrong in the class?Any thought on this would be helpful :)

Thanks in Advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081115/dde470eb/attachment.html>


More information about the Python-list mailing list