Posts

python call set property when property missing -

i have object has several properties containing values take while query. dont want values properties when create instance, when code path requires property few needed depending on code path. order when reach points int eh code not deterministic, cant set property @ fixed point in script. going create method def getvalue(self, attributename): if hasattr(self, attributename): return getattr(self, attributename) elif attributename == 'a1': v = ... code value a1 self.a1 = v return v elif attributename == 'a2': v = ... code value a2 self.a2 = v return v .... but wondering if way deal or if there smarter ways preferred. comment you can use decorator: class cached_property(object): """define property caching value on per instance basis. decorator converts method single self argument property cached on instance. """ def __init__(self, met...

c++ - Program with probability -

in event need generate probability, example bias coin 75% of tossing head , 25% tossing tail. conventionally, way: #include <cstdlib> #include <iostream> #include <ctime> using namespace std; int main() { int heads=0, tails=0; srand(time(null)); number = rand() % 100 + 1; //generate random number 1 100 if (number <= 75) //75% chance heads++; //this head else tails++; //this tail } this working code, when answered similar question on bias coin in user, of users mentioned multiple of 100. since random function generates uniform distribution, feels above code enough simulating probability event. in past posts, user bathsheba mentioned somehting multiples of 100: program simulates coin toss bias coin wanted know possible problems in code in relation that. my question is: above code acceptable code create simulation probability? or there flaws in these codes affect accuracy of simulated res...

reflection - String mapping to Java class fields -

do have idea of best practice or how can implement dynamical mechanism map string values java classes fields on runtime . this: iquote_id - should mapped current quote class - getid() method customer_name - should mapped current customer class - getname() method i have tried use reflection i'm not sure if solution since have fields coming direct classes, other superclasses , lot of if's me solve it..and want other elegant way if exists. how can build such mechanism? hint appreciated.thanks.

java - How to load dynamically a class with class.forName in JBOSS 7 -

i'm migrating web application jboss 7 , have problems class.forname method. i have 2 jars, each 1 in 1 different module: campuscomponentsjava-1.4.4.jar campusgateway-2.5.3-snapshot.jar the code campuscomponentsjava loads dynamically class campusgateway-2.5.3-snapshot.jar in following way: class.forname("edu.uoc.campusgateway.osid.authentication.authenticationmanager") i have created 2 modules in modules folder: <?xml version="1.0" encoding="utf-8"?> <module xmlns="urn:jboss:module:1.1" name="edu.uoc.oki2"> <resources> <resource-root path="campusgateway-2.5.3-snapshot.jar" /> <resource-root path="campuslauncherjava-1.1.3-snapshot-filter.jar"/> <resource-root path="okibusjava-1.2.2-config-uoc.jar"/> <resource-root path="okibusxmlschemas-1.1.1-snapshot.jar"/> <resource-root path="okiosid-2.0.jar...

module - Exporting Functions In Haskell -

i have haskell file named a.hs. have many helper functions, want export 2 of them, example foo1 , foo2. syntax corect? module (foo1,foo2) foo1 b = * b foo2 b = + b since there other helper functions in file, i'm not supposed reach them prelude after doing this, right? can reach them. i'm not sure do. how can solve problem? thanks in advance. the syntax correct. however, interpreted files, ghci makes toplevel functions available.

Invali attempt to call metadata when reader is closed c# winform -

this edited code removed try catch see getting exceptions. alse marked edited code. code getting on nerves have been googling problem , tried found. checked every connection other code there seems no problem them. each , every connection closed. querystring = "select * product prd_code = @c or prd_name=@pn "; sqlcommand command = new sqlcommand(querystring, con); command.parameters.addwithvalue("@c", convert.toint32(txtpcode.text)); command.parameters.addwithvalue("@pn", txtpname.text.tostring()); con.open(); //edited here using (sqldatareader dr = command.executereader()) { // , here if (dr != null && fr.hasrows && dr.read() == true) { if (txtpcode.text == "") { txtpcode.text = dr["prd_code"].tostring(); } else if (txtpname.text == "") { txtpname.text = dr["prd_name"].tostring(); ...

iOS Delegate not called -

for project need able send status "secondtableviewcontroller" "firsttableviewcontroller". followed tutorials on delegates don't seem work. when want call method in firsttableviewcontroller secondtableviewcontroller check see if "delegate" property empty, , every time is.. this code: secondtableviewcontroller.h @protocol sendstatusdelegate <nsobject> @required -(void)didstatuschanged; @end // eof delegate protocol @interface secondtableviewcontroller : uitableviewcontroller @property (nonatomic, assign) id<sendstatusdelegate> delegate; @end secondtableviewcontroller.m // status changed on row click - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { if (self.delegate) { // never called because delegate looks remain empty [self.delegate didstatuschanged]; } } firsttableviewcontroller.h @interface firsttableviewcontroller : uitableviewcontroller <sendstatusdeleg...