473,320 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Re: Unsubscriptable object when using Exec

On Fri, Nov 14, 2008 at 10:40 AM, Indian <wr*********@gmail.comwrote:
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
You don't need and shouldn't be using `exec` here. It appears as
though you're just doing the following in a much more obtuse and
unnecessarily complicated manner:

def OpenKey(rootkey, path, reg):
open_key = reg['HKLM']
for key in path.split('\\'):
open_key = open_key[key]
return open_key

Lesson: Don't use `exec`.
More importantly, what led you to think you needed to use it here in
the first place?

Cheers,
Chris
--
Follow the path of the Iguana...
http://rebertia.com
>
What am i doing wrong in the class?Any thought on this would be helpful :)

Thanks in Advance

--
http://mail.python.org/mailman/listinfo/python-list
Nov 15 '08 #1
0 1762

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jimmy Jim | last post by:
Hey all, quick question to see if anyone has any ideas. I have an object: $special = new special; Let's say I have a function: class special { function outputtext() { return "test";
2
by: Balaji | last post by:
Hello Everybody... I have a problem.. This is the code... -------------------------------------- class Stack: def __init__(self,expr): self.stackP=
5
by: ScottyBaby | last post by:
Hi, I've run into a curious problem with MS SQL Server 8.0. Using sp_help and SQL Query Analyzer's object browser to view the columns returned by a view, I find that sp_help is reporting stale...
3
by: Noloader | last post by:
Hello, We are using Access Front End (ADP Project) and SQL Server 2000 backend. SQL Server is using NT Security. We do not want the users to access the the underlying tables. So, we went to...
3
by: Robert Hogan | last post by:
Hello, I am attempting to send emails using T-SQL (in a SQLServerAgent Job) using the stored procedure sp_SendSMTPMail. I created the stored proc using the following script that I got off a post...
4
by: gman997 | last post by:
Hi all, At a high level here is what is going on -- I built a C# COM object. I need to call this com object from SQL Server using the sp_OACreate stored procedure in SQL Server. I build the COM...
9
by: k.retheesh | last post by:
Can anybody tell me why am I getting this error message while trying to print a part of a string. Is there a better approach for this... Traceback (most recent call last): File...
5
by: Jackson | last post by:
What is the difference between "object is unindexable" and "object is unsubscriptable"? I would like to test if an object can accept: obj TypeError: unindexable object TypeError:...
5
by: RyanN | last post by:
Hello, I'm trying to teach myself OOP to do a data project involving hierarchical data structures. I've come up with an analogy for testing involving objects for continents, countries, and...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.