Re: parse an environment file

Discussion in 'Python' started by Chris Angelico, Oct 1, 2012.

  1. On Tue, Oct 2, 2012 at 12:37 AM, Jason Friedman <> 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
    Chris Angelico, Oct 1, 2012
    #1
    1. Advertising

  2. On Monday, October 1, 2012 10:42:02 PM UTC+8, Chris Angelico wrote:
    > On Tue, Oct 2, 2012 at 12:37 AM, Jason Friedman <> 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


    I think one can ues some decorators to wrap OS or platform
    dependent functions.

    I am sure someone did that long time ago as the iron python
    wrapped dot-net.
    88888 Dihedral, Oct 1, 2012
    #2
    1. Advertising

  3. On Monday, October 1, 2012 10:42:02 PM UTC+8, Chris Angelico wrote:
    > On Tue, Oct 2, 2012 at 12:37 AM, Jason Friedman <> 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


    I think one can ues some decorators to wrap OS or platform
    dependent functions.

    I am sure someone did that long time ago as the iron python
    wrapped dot-net.
    88888 Dihedral, Oct 1, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason Friedman

    parse an environment file

    Jason Friedman, Oct 1, 2012, in forum: Python
    Replies:
    3
    Views:
    246
    Alain Ketterlin
    Oct 1, 2012
  2. Dave Angel

    Re: parse an environment file

    Dave Angel, Oct 1, 2012, in forum: Python
    Replies:
    0
    Views:
    188
    Dave Angel
    Oct 1, 2012
  3. Chris Angelico

    Re: parse an environment file

    Chris Angelico, Oct 1, 2012, in forum: Python
    Replies:
    0
    Views:
    235
    Chris Angelico
    Oct 1, 2012
  4. Jason Friedman

    Re: parse an environment file

    Jason Friedman, Oct 1, 2012, in forum: Python
    Replies:
    4
    Views:
    230
    Ramchandra Apte
    Oct 2, 2012
  5. Chris Angelico

    Re: parse an environment file

    Chris Angelico, Oct 1, 2012, in forum: Python
    Replies:
    0
    Views:
    235
    Chris Angelico
    Oct 1, 2012
Loading...

Share This Page