Python extend

Can anyone tell me why this bit of code is not working?

[code]statdata = system.db.runPrepQuery(“select stationNum, stationPre, stationName from stationlist where stationnum = ?”,[stationNum],database = myDB)

rtData = system.db.runPrepQuery(“select %s , %s, %s, %s from WWater where t_stamp Between ‘9/10/2011 0:00:00’ and ‘9/11/2011 0:00:00’” % (dailyRt,dailySrt,totRt,totSrt),database = myDB)


Running it gives me an attribute error on extend. With debug prints I have confirmed that the queries are returning the expected values now I just need to concatenate the lists.

My end game is to iterate through 22 stations and create a data set with 7 columns from the two queries above and 22 rows for a daily runtime report.


You can’t use “extend” in the jython version hat IA is using. If you look at the Python 2.7 docs, they give a subsitute to extend: “Extend the list by appending all the items in the given list; equivalent to a[len(a):] = L”. Give that a shot.

Also, I do a lot of stuff like you are doing, and if you have 22 stations, you may want to use “GROUP BY” and reduce it to one or two queries. Just a thought.

Thanks for the insight on extend. I am not having any luck with the equivalent either. I don’t know what my issue is. Hopefully it’s not fatigue induced idiocy. Out of curiosity, could you be more specific on the “GROUP BY”. I know what the GROUP BY statement is, but I am not seeing how exactly it gets me to my end game.

My historical data is stored in a single table, I am calculating the daily runtime by subtracting the MAX runtime from the MIN runtime in an sql statement with a WHERE clause of t_stamp within a day.

I originally wrote out some inordinately long select statements which worked, but the single row couple hundred column dataset was not friendly for inserting them in a report using the reporting module (other than inserting them individually one at a time). I am now trying to create a dataset with a column for station name (from another table), daily runtime, daily start count, daily runtime per start, total runtime and total start count with a row for each station so I can group them in a table.

Any ideas would be great.


I tried the extend equivalent, and it seems to work as intended. Aren’t you just concatenating two lists?

a[len(a):] = b
print a

Regarding the group by, I’m not sure what you are doing, so maybe it wouldn’t help. At a minimum though, I would get all the rows for all stations in a single query and iterate through them as needed instead of doing it one query at a time.