Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #30607

Re: parse an environment file

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'bash': 0.07; 'skip:/ 10': 0.07; 'subject:file': 0.07; 'python': 0.09; 'imported.': 0.09; 'received:mail-vc0-f174.google.com': 0.09; 'scripts,': 0.09; 'subset': 0.09; 'itself.': 0.11; 'value.': 0.15; 'ah,': 0.16; 'consciously': 0.16; 'dictionary,': 0.16; 'enough.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'merely': 0.16; 'oct': 0.16; 'wrote:': 0.17; 'config': 0.17; 'exists': 0.17; 'instance,': 0.17; 'module': 0.19; 'variable': 0.20; 'file.': 0.20; 'parse': 0.22; "i'd": 0.22; "i've": 0.23; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'format,': 0.27; 'restrict': 0.27; 'message-id:@mail.gmail.com': 0.27; 'oversight': 0.29; 'received:209.85.220.174': 0.29; 'file': 0.32; 'could': 0.32; 'to:addr:python-list': 0.33; 'version': 0.34; 'received:google.com': 0.34; 'jason': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'next': 0.35; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'easily': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'your': 0.60; 'range': 0.60; 'times': 0.63; 'making': 0.64; 'stated': 0.69; 'hoping': 0.72; 'yourself': 0.77; 'object:': 0.84; 'viable': 0.84; 'severe': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=LGWVHWi7c8gUqCVZz5nk36KLmZQLaluxLptd+WaY+vU=; b=Nw1IzGQCrpkgzoLiox8T07sLlzqR1CDMwD3AvkNNipl+2If6+DEWkj6zphPR2GRHKF oCEEz86WecdZRa1hMs8g5ZCp+Bta3VVocI5rDNtlwPeLonzNbM1ZlQUq7358FTzs2YsI Kvzotmyklo1iuz6fCqaDC9OylXfGH645wO0rL3t9K8Pim1441KYclKAa7AsW4jj2z6Dg FdwwcEsjSpnc8IPIMQ0G7HCwyBPuvu1Lsu2vM0oQqVevm0PaAfFCJYFgJsr749POt1yV tIFp02Yn/z0jTtmVmhQQBHoZ5Z5YU54i4wMvGp5dRMaR+xr96kfJFlASJMjdVHHCm5Jf oaOw==
MIME-Version 1.0
In-Reply-To <CANy1k1hzHqODvV7Eu64maOfCx8Os48wro56HG=uheyjqUos-uQ@mail.gmail.com>
References <CANy1k1i7XA3pTGeZeWk8V4osPkRoWxkSQJehhix9nHzDzO3HTg@mail.gmail.com> <CANy1k1g1dt6GQR80LWMkBt+YXzZXxtkUSV=qamWsS8mZXiyaAA@mail.gmail.com> <CAPTjJmrcsPgtcy6Aa5KJ8mRjFuB5b-FBanVQJ1o0M_PnHVpL2w@mail.gmail.com> <CANy1k1hzHqODvV7Eu64maOfCx8Os48wro56HG=uheyjqUos-uQ@mail.gmail.com>
Date Tue, 2 Oct 2012 00:41:58 +1000
Subject Re: parse an environment file
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.1705.1349102521.27098.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1349102521 news.xs4all.nl 6939 [2001:888:2000:d::a6]:55159
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:30607

Show key headers only | View raw


On Tue, Oct 2, 2012 at 12:37 AM, Jason Friedman <jason@powerpull.net> wrote:
>> Is there a reason to use that format, rather than using Python
>> notation? I've at times made config files that simply get imported.
>> Instead of a dictionary, you'd have a module object:
>>
>>
>> # config.py
>> VAR1='foo'
>> VAR2='bar'
>> VAR3=VAR1+VAR2
>>
> There is a reason:  /path/to/export_file exists for Bash scripts, too,
> and I do not think I could get Bash to read config.py in the format
> stated above.  I want to maintain only one file.

(Responding on-list and hoping it was merely oversight that had that
email come to me personally)

Ah, fair enough. Well, since you're using the full range of bash
functionality, the only viable way to parse it is with bash itself.
I'd recommend going with the version you have above:

> * * * * * . /path/to/export_file && /path/to/script.py

Under what circumstances is this not an option? That'd be the next
thing to consider.

Alternatively, you may want to consider making your own config file
format. If you consciously restrict yourself to a severe subset of
bash functionality, you could easily parse it in Python - for
instance, always look for "export %s=%s" with simple strings for the
variable name and value.

ChrisA

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: parse an environment file Chris Angelico <rosuav@gmail.com> - 2012-10-02 00:41 +1000
  Re: parse an environment file 88888 Dihedral <dihedral88888@googlemail.com> - 2012-10-01 08:29 -0700
  Re: parse an environment file 88888 Dihedral <dihedral88888@googlemail.com> - 2012-10-01 08:29 -0700

csiph-web