Qurying a TinyTable (plus)
Hi List, Have developed a parameter driven process which is driven by a list of sets of parameters listed in a tiny table. Am trying to find the correct syntax to pull out a given column where the index is specified, in a python script. Can anyone give me a clue, or point to a fuller example than those in the TinyTable docs please? (Google doesn't have much to say on this - examples are all DTML, or driven by more than the requirement to pull a single value out!) -- Regards, PhilK Email: phil@xfr.co.uk / Voicemail & Facsimile: 07092 070518 "The lyf so short, the craft so long to learne" - Chaucer
Philip Kilner wrote:
Hi List,
Have developed a parameter driven process which is driven by a list of sets of parameters listed in a tiny table. Am trying to find the correct syntax to pull out a given column where the index is specified, in a python script.
Can anyone give me a clue, or point to a fuller example than those in the TinyTable docs please?
Say you have: TinyTable : mytable Columns : mykey myvalue mykey myvalue --------------- "1" "One" "2" "Two" Then: value1 = mytable(mykey="1")[0]['myvalue'] value1 = mytable(mykey="2")[0]['myvalue'] Mark
Hi Mark, Mark Gibson wrote:
Can anyone give me a clue, or point to a fuller example than those in the TinyTable docs please?
Say you have:
TinyTable : mytable Columns : mykey myvalue mykey myvalue --------------- "1" "One" "2" "Two"
Then:
value1 = mytable(mykey="1")[0]['myvalue'] value1 = mytable(mykey="2")[0]['myvalue']
Thanks very much - that worked first time! I now have: - container.REQUEST.SESSION.set('process_spec', container.process_spec(step='1')[0]['form_name']) ...so with your help I now have the bones of something I can automate. My only problem is that I don't /really/ understand how it works! Clearly, process_spec(step='1') is referring to the index of my TinyTable. But the significance of [0] and the way in which ['form_name'] seems to be "outside" the clause are confusing the hell out of me! Anyone kind enough to clue me in? -- Regards, PhilK Email: phil@xfr.co.uk / Voicemail & Facsimile: 07092 070518 "The lyf so short, the craft so long to learne" - Chaucer
Philip Kilner wrote:
Hi Mark,
Mark Gibson wrote:
Can anyone give me a clue, or point to a fuller example than those in the TinyTable docs please?
Say you have:
TinyTable : mytable Columns : mykey myvalue mykey myvalue --------------- "1" "One" "2" "Two"
Then:
value1 = mytable(mykey="1")[0]['myvalue'] value1 = mytable(mykey="2")[0]['myvalue']
My only problem is that I don't /really/ understand how it works! Clearly, process_spec(step='1') is referring to the index of my TinyTable. But the significance of [0] and the way in which ['form_name'] seems to be "outside" the clause are confusing the hell out of me!
Anyone kind enough to clue me in?
mytable() querys the tt and returns a list of dictionaries ( or at least something that implements a dictionary interface). Any query to the tt will return a list of dictionaries. So for the above example: mytable() will return all the rows in the tt: [ { "mykey":"1", "myvalue":"One" }, { "mykey":"2", "myvalue":"Two" } ] Given this, mytable(mykey="1") will return: [ {"mykey":"1", "myvalue":"One"}, ] From there, you should be able to figure out what the rest of it does. Mark
Hi Mark, Mark Gibson wrote:
mytable() querys the tt and returns a list of dictionaries ( or at least something that implements a dictionary interface). Any query to the tt will return a list of dictionaries.
So for the above example: mytable() will return all the rows in the tt: [ { "mykey":"1", "myvalue":"One" }, { "mykey":"2", "myvalue":"Two" } ]
Given this, mytable(mykey="1") will return: [ {"mykey":"1", "myvalue":"One"}, ]
From there, you should be able to figure out what the rest of it does.
I'm going to go away and play with that - time to give "Learning Python" some more hammer! Thanks again! -- Regards, PhilK Email: phil@xfr.co.uk / Voicemail & Facsimile: 07092 070518 "The lyf so short, the craft so long to learne" - Chaucer
Philip Kilner wrote at 2004-5-4 18:29 +0100:
... Can anyone give me a clue, or point to a fuller example than those in the TinyTable docs please?
Look at the source (or use "DocFinder") to learn what methods are available. <http://www.dieter.handshake.de/pyprojects/zope> -- Dieter
participants (3)
-
Dieter Maurer -
Mark Gibson -
Philip Kilner