Problem with variables assigned to variables???

Lutz Horn lutz.georg.horn at googlemail.com
Wed Apr 30 08:41:47 CEST 2008


Hi,

2008/4/30  <grepla at gmail.com>:
>  mylist = ('name1', 'name2', 'name3')
>
>  I also assigned variables for each SQL expression:
>  name1 = "\"field_a\" LIKE '021'"
>  name2 = "\"field_a\" LIKE '031'"
>  name3 = "\"field_a\" LIKE '041'"

>  my intended output is:
>  name1.shp "field_a LIKE '021'
>  name2.shp "field_a LIKE '031'
>  name3.shp "field_a LIKE '041'

You should use a dictionary someway like this:

>>> mydict = {'name1':"\"field_a\" LIKE '021'",
... 'name2':"\"field_a\" LIKE '031'",
... 'name3':"\"field_a\" LIKE '041'"}
>>> for key, value in mydict.items():
...     print key, value
...
name2 "field_a" LIKE '031'
name3 "field_a" LIKE '041'
name1 "field_a" LIKE '021'

Lutz

-- 
Do you want a Google Mail invitation? Just write me an email!



More information about the Python-list mailing list