473,378 Members | 1,688 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,378 software developers and data experts.

Grabbing a object from the current code block using a callable statement?

Hi

Is it possible to grab get an object returned from a string and a
callable ? e.g

I pass in a key value pair:

def somemethod(adict = {'new name for object': '<code to reutrn
obejct>'}):

object = .....

for key, value in adict.items():
if callable(value):
somedict[key] = value()
else:
somedict[key] = value

such that

somedict = {'new name for object': object}

??

Thanks,

Feb 25 '06 #1
1 1150
ChaosKCW wrote:
Hi

Is it possible to grab get an object returned from a string and a
callable ? e.g

I pass in a key value pair:

def somemethod(adict = {'new name for object': '<code to reutrn
obejct>'}):

object = .....

for key, value in adict.items():
if callable(value):
somedict[key] = value()
else:
somedict[key] = value

such that

somedict = {'new name for object': object}

??

Thanks,


If you are asking if an object instance can be stored in a dictionary
the answer is yes.

example:
class foo: .... def method(self):
.... print "in foo.method"
.... return
.... adict={'fooclass': foo()}
adict['fooclass'].method() in foo.method


Instances of classes are just like any other data you might put into
a list or a dictionary. I hope that is what you were asking.

-Larry Bates
Feb 25 '06 #2

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

Similar topics

2
by: Aaron | last post by:
I have a data sructure setup and I populate it in a loop like so: y=0 while X: DS.name = "ASDF" DS.ID = 1234 list = DS; y = y + 1
1
by: ronvhill | last post by:
I am encountering an error on the following code. Basically, I have two queries which I am using to enter new records into two other tables, one a master and the other a child. Function...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
9
by: grbgooglefan | last post by:
I am trying to pass a C++ object to Python function. This Python function then calls another C++ function which then uses this C++ object to call methods of that object's class. I tried...
7
by: iu2 | last post by:
Hi, Playing with imitating lambdas and ruby blocks in Python, I came up with a very simple construct, for example: import compiler def dotimes(i, code): for i in range(i): exec code
0
by: Jean-Paul Calderone | last post by:
On Tue, 29 Jul 2008 07:26:38 -0700 (PDT), "jiri.zahradil@gmail.com" <jiri.zahradil@gmail.comwrote: Python doesn't have dynamic scoping. ... for i in range(n): ... callable()...
9
by: Duggi | last post by:
I used to wonder why MS implemented C# to accept the following code using (Font f = new Font()) { // some code here. } While the same can be achieved through {
12
by: Duggi | last post by:
I used to wonder why MS implemented C# to accept the following code using (Font f = new Font()) { // some code here. } While the same can be achieved through {
6
by: netimen | last post by:
Can I substitute a method of a class by a callable object (not a function)? I can very easy insert my function in a class as a method, but an object - can't. I have the following: class...
1
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.