I am new to Python. I have been studying the concept of python classes recently. Well, for a couple of the scripts I wrote, I thought it would be convenient to define a class that combines the SQL statement (in the ArcGis dialect). Nothing special. Here is what I came up with. I ask two things: first, common flaws? Suggestions for improvement? Secondly, I got a bit stuck in the code of the last def constructor function. In fact, I want to return a tuple from the dictionary, not a list. But understanding the list is nice. So what about the generator? I canβt figure out exactly how to do this ...
class ArcSql: type_book = {'str':("'","'"), 'int':("", "")} format_book = dict(shp=("'","'"), GDB=("[","]")) def __init__(self,colom_name, values_list, value_type = 'str', arc_format ='shp'): self.colom = colom_name self.values = values_list self.valtype = self.constructor(type_book, value_type) self.aformat = self.constructor(format_book, arc_format) self.colom_formated = str(self.aformat[0][0]) + self.colom + str(self.aformat[0][1]) def statement(self): temp_state = [] connector = "'OR' " count_values = len(self.values) if count_values == 0: return("error, not enough values...") else: for v in self.values: x = self.colom_formated + " = " + str(self.valtype[0][0]) + v + str(self.valtype[0][1]) + ' ' + connector temp_state.append(str(x)) state = "".join(temp_state)[:-5] return(str(state)) def constructor(self, book, book_key): return([v for k,v in book.iteritems() if k==book_key])
source share