Re: [Tutor] Reference a variable from a string whose value is the name of the variable

2006-06-06 Thread Patrick Wheeler
>data = [ ]>for i in xrange(1,101):> data = "" %i  _n, f %i_v)) The function locals() will return a dictionary of variables in the current scope.  This can then be used to reference variables by name. x=1 xname = 'x' print locals()['x'] print locals()[xname] This prints: 1 1 or for your example.

Re: [Tutor] Reference a variable from a string whose value is the name of the variable

2006-06-06 Thread Kent Johnson
Peter Jessop wrote: > Kent > > Thanks for your reply. > The structure is for sending form variables and values to a web server > with POST. > I am using urllib.urlencode which accepts a list or dictionary as argument. > > The idea is to look for airline tickets. > The airline I buy from only lets

Re: [Tutor] Reference a variable from a string whose value is the name of the variable

2006-06-06 Thread Peter Jessop
Kent Thanks for your reply. The structure is for sending form variables and values to a web server with POST. I am using urllib.urlencode which accepts a list or dictionary as argument. The idea is to look for airline tickets. The airline I buy from only lets me search by data but I want to autom

Re: [Tutor] Reference a variable from a string whose value is the name of the variable

2006-06-05 Thread Kent Johnson
Peter Jessop wrote: > Thanks Andre > > I realise now I did not make it too clear. > Basically the variable names are predictable but the values aren't. > > Maybe I should have expressed it like this > > f0_n = "arbitrayValue" > f0_v ="another valule" > f1_n="something else" > f1_v="etc.." > ...

Re: [Tutor] Reference a variable from a string whose value is the name of the variable

2006-06-05 Thread Peter Jessop
André Thanks a lot for clearing this up for me. Regards Peter Jessop ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Reference a variable from a string whose value is the name of the variable

2006-06-05 Thread Andre Roberge
On 6/5/06, Peter Jessop <[EMAIL PROTECTED]> wrote: Thanks AndreI realise now I did not make it too clear.Basically the variable names are predictable but the values aren't.I assumed that.  I just recreated the list as you gave it because it was easy :-) Maybe I should have expressed it like thisf0_

Re: [Tutor] Reference a variable from a string whose value is the name of the variable

2006-06-05 Thread Peter Jessop
Thanks Andre I realise now I did not make it too clear. Basically the variable names are predictable but the values aren't. Maybe I should have expressed it like this f0_n = "arbitrayValue" f0_v ="another valule" f1_n="something else" f1_v="etc.." ... f100_n = "another value" f100_v = "nexvalue

Re: [Tutor] Reference a variable from a string whose value is the name of the variable

2006-06-05 Thread Andre Roberge
I'm not sure if it's exactly what you need, but here's something that may come close.On 6/5/06, Peter Jessop <[EMAIL PROTECTED] > wrote:The best way to explain my problem is with an examplef0_n = "field0" f0_v ="value0"f1_n="field1"f1_v="value1"...f100_n = "field100"f100_v = "value100"Ok, I'm going