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

Kent Johnson kent37 at tds.net
Tue Jun 6 14:07:03 CEST 2006


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 me search by data but I want to
> automate the process by POSTing the form for a range of dates so that
> effectively I can search by price not by date.
> I will then parse the returned HTML using HTMLParser or BeautifulSoup.
> 
> The form has a large number of variables and I just want to find a
> tidy way to organise the information.

It sounds like you should use a dictionary directly as your primary data 
structure. For data that is fixed just use a literal dictionary, for example
args = dict(origin='SJO', destination='MHO')

For dates, you presumably have some kind of loop to generate dates in a 
range, then insert them into the dict:
for date in <list of dates>:
   args['date'] = date
   # fetch and parse the URL with args as the POST data

Kent




More information about the Tutor mailing list