[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math

Search:


View post   

>> No.5258844 [View]
File: 35 KB, 578x477, 1303723185145.jpg [View same] [iqdb] [saucenao] [google]
5258844

I thought this is the best place to ask this question.

Currently, I want to write a python class that just holds some dictionary and references to certain functions. I want to make it possible to write these functions outside the class, but wish to have the functions use the namespace as if it is within the class.

For example

class A:
def __init__(self, some_dict, func_a, func_b):
self.memory = some_dict
self.__call__ = func_a
self.__repr__ = func_b

def some_func(self, some_input):
if some_input in self.memory :
return self.memory[some_input]
else :
self.memory[some_input] = 1.
return 1.

first_object = A({}, some_func, some_func)

This will work if I call the object as follows:
first_object(first_object, '5'), but I wish to do the same without also putting the object itself in the call. Is this even remotely possible or is it just that namespace fucks things up?

The reason for this is to keep the class very simple and clear, whereas the functions outside it can be dynamically built on the fly. The object is just to keep track of what it has accumulated and make easy operations on itself.

Anyone?

>> No.5007979 [View]
File: 35 KB, 578x477, 1344358821808.jpg [View same] [iqdb] [saucenao] [google]
5007979

>>5007800
YES

>> No.1999431 [View]
File: 35 KB, 578x477, 1288477396950.jpg [View same] [iqdb] [saucenao] [google]
1999431

Hey /sci/, need some help with a college pre-lab. It's finding delta H for a reaction. This is all they gave us.

Mg(s) + 2HCL(aq) ---> MgCl2(aq) + H2(g)

the magnesium weighs .153 g; Ti = 24.3 C; Tf = 38.5 C

I really don't see how I'm supposed to figure this out with a specific heat.

>> No.1168420 [View]
File: 35 KB, 578x477, 1267444865712.jpg [View same] [iqdb] [saucenao] [google]
1168420

Mmmm... pringles

Navigation
View posts[+24][+48][+96]