Re: [Tutor] get name of calling class at runtime
"Kent Johnson" wrote can group a bunch of SQL statements in one place; they're currently scattered all over the program and it's getting unwieldy). Normally in an OO program the SQL for each class is in the methods for that class. That way any changes to the class canbe easily reflected in the related SQL. But if all the classes need nearly the same SQL, it may make sense to abstract that out to a common location.That is what Serdar is trying to do. Duplication is also a bad smell. Thats not what he said, he says he wants to collect SQL thats scattered into one location. And his pseudo code has the classic procedural case statement to select the right SQL depending on class. He is not calling a single parameterised piece of SQL... Thats the bad smell. If the SQL is common then the OO way to handle that would be to write a mixin class called, say, Storable that accessed the real instance attributes(like tablename). That could then be inherited by all Storable objects. That way you get the common code and avoid the case statement based on type. PS. I know Kent knows about mixins, the explanation was for anyone else who is intrested :-) HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] simple plots
"questions anon" wrote I would like to make some simple plots using matplotlib (or any python plotting modules) and I can find lots of examples that generate random data and then plot those, but I cannot find any that read in data from excel or a text file, manipulate the data and then plot the data. Is your question about how to use matplotlib or how to acquire data. matplotlib doesn't care where the data comes from, the examples only use random data because its easy to produce. But the data can come from anywhere, that's a completely separate process to plotting it. So do you know how to get the data and maniplulate it? Is that really what you are asking? If so we need to know a bit more about what kind of data)its format) and what kind of manipulation you want to do - is it statistical, scientific calculation, parsing etc? There will almost certainly be some modules that can help but we can't tell which yet. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] get name of calling class at runtime
On Sat, Aug 22, 2009 at 3:54 AM, Alan Gauld wrote: > "Kent Johnson" wrote > can group a bunch of SQL statements in one place; they're currently scattered all over the program and it's getting unwieldy). >>> >>> Normally in an OO program the SQL for each class is in the methods for >>> that >>> class. That way any changes to the class canbe easily reflected in the >>> related SQL. >> >> But if all the classes need nearly the same SQL, it may make sense to >> abstract that out to a common location.That is what Serdar is trying >> to do. Duplication is also a bad smell. > > Thats not what he said, he says he wants to collect SQL thats scattered > into one location. And his pseudo code has the classic procedural > case statement to select the right SQL depending on class. He is not > calling a single parameterised piece of SQL... Thats the bad smell. Ah, right. I was reading more into the OP than was there. I think it does makes sense to keep SQL confined to well-defined locations. This can be per class - each class holds its own SQL - or a single class that does all database access so all SQL and database dependencies are in one place. But in this case if different clients needed different functionality I would make different methods for them. Rather than class DataSources(object): def getdata(self, caller): if caller == 'CallerA': # execute sql for callerA elif caller == 'CallerB': #execute sql for callerB it is reasonable to have class DataSources(object): def getAdata(self): # execute sql for callerA def getBdata(self): #execute sql for callerB etc. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] get name of calling class at runtime
"Kent Johnson" wrote I think it does makes sense to keep SQL confined to well-defined locations. This can be per class - each class holds its own SQL - or a single class that does all database access so all SQL and database dependencies are in one place. My vote for the class every time. I hate having to make changes in two places when I add an attribute etc. Especially if they are in two separate files or the classes are beiong used in multiple projects. All that regression testing becomes a headache. class DataSources(object): def getAdata(self): # execute sql for callerA def getBdata(self): #execute sql for callerB You might as well just put them as functions in a module, but you still have the double file maintenance issue. -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor