Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'filename': 0.09; 'files.': 0.09; 'am,': 0.12; 'def': 0.15; 'lookup': 0.16; 'simple:': 0.16; '\xc2\xa0i': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.16; 'subject:list': 0.18; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'variable': 0.24; 'aug': 0.24; 'loop': 0.28; 'thu,': 0.28; 'mapping': 0.29; 'message- id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.30; 'strings.': 0.30; 'values,': 0.30; 'list': 0.32; 'pointing': 0.32; 'things': 0.34; 'skip:" 20': 0.35; 'subject:How': 0.35; 'variables': 0.37; 'passed': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'skip:d 20': 0.39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=pdgmOBu+mdFg7w5xFexNFxJiEfsHMqM1sfymm7WAe6s=; b=VcouyKwQPhLYTEeMxBMffr3wEvWIZbVl+05/cH/UGnKRnHUEUmqZcFhSI+MxoGsXuY L0KH78a+3413NlX7z1W6bRB8Q5GUZrnljtbzMAWYP6S2QVb/1GrZq4HWtm3J8H08TYW6 9J3jo+fC4YlG936U3TRDOys4Mi2G7CcO6/nvc= MIME-Version: 1.0 In-Reply-To: <5db667e8-d8af-42ef-9098-5b299e1a81d9@y16g2000yqk.googlegroups.com> References: <2ab25f69-6017-42a6-a7ef-c71bc2ee8547@l2g2000vbn.googlegroups.com> <5db667e8-d8af-42ef-9098-5b299e1a81d9@y16g2000yqk.googlegroups.com> Date: Thu, 18 Aug 2011 11:29:40 -0400 Subject: Re: How to convert a list of strings into a list of variables From: Jerry Hill To: noydb Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1313681381 news.xs4all.nl 23939 [2001:888:2000:d::a6]:46242 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11769 On Thu, Aug 18, 2011 at 11:19 AM, noydb wrote: > I am being passed the list of strings. =C2=A0I have variables set up > already pointing to files. =C2=A0I need to loop through each variable in > the list and do things to the files. =C2=A0The list of strings will chang= e > each time, include up to 22 of the same strings each time. If you have a mapping of strings to values, you should just go ahead and store them in a dictionary. Then the lookup becomes simple: def foo(list_of_strings): mapping =3D { "bar0": "/var/log/bar0.log", "bar1": "/usr/local/bar/bar1.txt", "bar2": "/home/joe/logs/bar2.log", } for item in list_of_strings: filename =3D mapping[item] do_something(filename) (Untested) --=20 Jerry