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

def obj()

def obj():
return {'data':'hello',
'add':add(v)}

def add(v):
data=data+v

if __name__ == '__main__':
test=obj()
test.add('world')
print test.data

I don't know why but i have one of does none class c programing style
moods again. I was wondering if the following was possible without
using a class ?
Feb 8 '07 #1
3 1081
Gert Cuykens wrote:
def obj():
return {'data':'hello',
'add':add(v)}

def add(v):
data=data+v

if __name__ == '__main__':
test=obj()
test.add('world')
print test.data

I don't know why but i have one of does none class c programing style
moods again. I was wondering if the following was possible without
using a class ?
def obj():
result = {'data': 'hello'}
result['add'] = adder(result)
return result

def adder(obj):
def add(value):
obj['data'] += value
return add

if __name__ == '__main__':
test = obj()
test['add']('world')
print test['data']
Feb 8 '07 #2
On 2/8/07, Leif K-Brooks <eu*****@ecritters.bizwrote:
def obj():
result = {'data': 'hello'}
result['add'] = adder(result)
return result

def adder(obj):
def add(value):
obj['data'] += value
return add

if __name__ == '__main__':
test = obj()
test['add']('world')
print test['data']
Nice :) Does anybody know how this would look in c code ?
Feb 8 '07 #3
#include <stdio.h>

function hello(){
struct obj = { char *data = 'hello'}
obj.add = obj_add(obj);
return obj;
}

function obj_add(obj){
function add(value){
obj.data += value;
return obj;
}
}

main(){
test = hello();
test.add('world');
printf(test.data);
}

I was thinking something like this maybe ?
Feb 8 '07 #4

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

Similar topics

7
by: Steven C. | last post by:
When you compile a cpp program that includes a template class in a .h file where does the compiled code go for that templated class? If it went in the obj for the cpp program seems to me you could...
4
by: Akhil | last post by:
Hi All, Can u please explain this. Base Obj = new Derived(); Can Obj access methods both of Base and Derived or what will be the behaviour? What will be the behaviour for Overridden...
8
by: consultutah | last post by:
I am trying to upgrade from VS7.1 to VS8, but whenever I link any of our MC++ DLL's, I get the following errors: Creating library \sda\Main\bin\debug\XWRAP70.lib and object...
3
by: Mark Kamoski | last post by:
Hi-- What is the difference between Convert.ToString(obj) and CType(obj, String)? (Assume obj is a variable of type Object.) Please advise. Thank you.
1
by: sethuganesh | last post by:
HI, i have ported vc++ 6.0 code to visual studio 2005. During batch build in debug mode i din't get any error.But if i build the same in release mode i am getting the following error. ...
9
by: alf | last post by:
Hi, I have a reference to certain objects. What is the most pythonic way to test for valid reference: if obj: if None!=obs: if obj is not None:
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
3
by: john_owens | last post by:
I have a templated function called splitAndSegment (templated on the datatype). It's declared in a header file. I then include that header file in two separate cpp files and link them separately....
3
by: Eric Layman | last post by:
Hi, I have a script here which will loop thru a table and check for it's background color. But it doesn't work on Firefox. The Error Inspector said "ERROR. obj.cells has no properties How...
40
by: gert | last post by:
#include <stdio.h> obj function hello(){ struct obj = { char *data = 'hello'} obj.add = obj_add(obj); return obj; } void function obj_add(obj){ obj function add(value){
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.