Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #11769
| 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 | <malaclypse2@gmail.com> |
| 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> <mailman.167.1313680359.27778.python-list@python.org> <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 <malaclypse2@gmail.com> |
| To | noydb <jenn.duerr@gmail.com> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.168.1313681381.27778.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
On Thu, Aug 18, 2011 at 11:19 AM, noydb <jenn.duerr@gmail.com> wrote:
> I am being passed the list of strings. I have variables set up
> already pointing to files. I need to loop through each variable in
> the list and do things to the files. The list of strings will change
> 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 = {
"bar0": "/var/log/bar0.log",
"bar1": "/usr/local/bar/bar1.txt",
"bar2": "/home/joe/logs/bar2.log",
}
for item in list_of_strings:
filename = mapping[item]
do_something(filename)
(Untested)
--
Jerry
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to convert a list of strings into a list of variables noydb <jenn.duerr@gmail.com> - 2011-08-18 07:57 -0700
Re: How to convert a list of strings into a list of variables David Robinow <drobinow@gmail.com> - 2011-08-18 11:12 -0400
Re: How to convert a list of strings into a list of variables noydb <jenn.duerr@gmail.com> - 2011-08-18 08:19 -0700
Re: How to convert a list of strings into a list of variables Jerry Hill <malaclypse2@gmail.com> - 2011-08-18 11:29 -0400
Re: How to convert a list of strings into a list of variables noydb <jenn.duerr@gmail.com> - 2011-08-18 08:54 -0700
Re: How to convert a list of strings into a list of variables John Gordon <gordon@panix.com> - 2011-08-18 16:09 +0000
Re: How to convert a list of strings into a list of variables Chris Angelico <rosuav@gmail.com> - 2011-08-18 18:48 +0100
Re: How to convert a list of strings into a list of variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-19 11:42 +1000
Re: How to convert a list of strings into a list of variables Nobody <nobody@nowhere.com> - 2011-08-18 19:45 +0100
Re: How to convert a list of strings into a list of variables AB <antonio.a.barbosa@gmail.com> - 2011-08-18 15:05 -0700
Re: How to convert a list of strings into a list of variables Kingsley Adio <adiksonline@gmail.com> - 2011-08-19 00:39 -0700
Re: How to convert a list of strings into a list of variables Roy Smith <roy@panix.com> - 2011-08-19 08:57 -0400
Re: How to convert a list of strings into a list of variables noydb <jenn.duerr@gmail.com> - 2011-08-19 07:32 -0700
csiph-web