Thanks Chris!!<br><br>It worked.. Yeah my bad i was trying out the bad logic :)<br><br><div class="gmail_quote">On Sat, Nov 15, 2008 at 5:31 AM, Chris Rebert <span dir="ltr"><<a href="mailto:clp@rebertia.com">clp@rebertia.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="Wj3C7c">On Fri, Nov 14, 2008 at 10:40 AM, Indian <<a href="mailto:write2abdul@gmail.com">write2abdul@gmail.com</a>> wrote:<br>

> Hi Friends<br>
><br>
> I'm getting the TypeError Unsubscriptable object when using Exec in a class<br>
><br>
> Here's the example<br>
><br>
> class Fake(object):<br>
>   def __init__(self, reg):<br>
>     self._reg = reg<br>
><br>
>   def OpenKey(self, rootkey, path):<br>
>     open_key = self._reg<br>
>     path_string='[\'HKLM\']'<br>
>     for key in path.split('\\'):<br>
>       path_string += '[\'%s\']'%key<br>
>     a='d=open_key%s'%path_string<br>
>     exec(a)<br>
>     return d<br>
><br>
> When i create a claassobject and call the method Openkey i get the above<br>
> error but it works fine in the below example without class<br>
><br>
> def OpenKey(rootkey, path, reg):<br>
>   open_key = reg<br>
>   path_string='[\'HKLM\']'<br>
>   for key in path.split('\\'):<br>
>     path_string += '[\'%s\']'%key<br>
>   a='d=open_key%s'%path_string<br>
>   print a<br>
>   exec(a)<br>
>   return d<br>
<br>
</div></div>You don't need and shouldn't be using `exec` here. It appears as<br>
though you're just doing the following in a much more obtuse and<br>
unnecessarily complicated manner:<br>
<div class="Ih2E3d"><br>
def OpenKey(rootkey, path, reg):<br>
</div>    open_key = reg['HKLM']<br>
<div class="Ih2E3d">    for key in path.split('\\'):<br>
</div>        open_key = open_key[key]<br>
    return open_key<br>
<br>
Lesson: Don't use `exec`.<br>
More importantly, what led you to think you needed to use it here in<br>
the first place?<br>
<br>
Cheers,<br>
Chris<br>
--<br>
Follow the path of the Iguana...<br>
<a href="http://rebertia.com" target="_blank">http://rebertia.com</a><br>
<div class="Ih2E3d"><br>
><br>
> What am i doing wrong in the class?Any thought on this would be helpful :)<br>
><br>
> Thanks in Advance<br>
><br>
</div>> --<br>
> <a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
><br>
</blockquote></div><br>