Re: [Zope] python method query
Lee Reilly CS1997 wrote:
Hi Chris,
Is it possible to call a Python method from a Python method
Yes
Can you tell me how exactly?
I think you need to provide a lot more information about what you're actually trying to do ;-) Also, keep CC'ing in the list... cheers, Chris
populate_table_unchecked(matric, classcode, self) # create a database connection # querys the database # parse the results # derives new queries based on results # returns some parameters e.g. p, a, t, b # and some other things I'm using this code in a lot of my methods so I'd rather have it in one. I know I can put a .py file in my extenstions directory and call it that way but is there any way to call it (as a Python method) from another Python method? Here's part of the method populate_table_unchecked(matric, classcode, self) table="CLASS" + string.replace(`classcode`, ".", "") table=string.replace(table, "'", "") db_conn = self.MySQL_database_connection() SQL = ("SELECT PRACTICALS, ASSIGNMENTS, TUTORIALS, BONUS FROM CLASSES WHERE CLASSCODE = '" + classcode + "'") result=db_conn.query(SQL) resultString = `(result[1])` length = len(resultString) # To take away the last 2 brackets i=length-1 x= "" while (i>1): x=x+resultString[length-1-i] i=i-1 # To take away the first 2 brackets newLength=len(x) j=newLength-1 y= "" while (j>1): y=y+x[j] j=j-1 # To invert the string i=len(y)-1 z="" while (i>=0): z=z+y[i] i=i-1 components = string.split(z) p = string.atoi(string.replace(components[0], ",", "")) a = string.atoi(string.replace(components[1], ",", "")) t = string.atoi(string.replace(components[2], ",", "")) b = string.atoi(components[3]) ... how would I call it from another Python method? i.e. pass is values for class & matric and allow it to return p,a,t and b? Would I need to use 'def' in addition to giving my method an id and parameter list? Thanks for any help. Lee
participants (2)
-
Chris Withers -
Lee Reilly CS1997