property file

Discussion in 'Python' started by Mariano, Jun 11, 2004.

  1. Mariano

    Mariano Guest

    Hi

    Have someone any idea how create/read a property file as java property file?
    If not, is there some other solutions?

    Thank's in advance
    Mariano, Jun 11, 2004
    #1
    1. Advertising

  2. Mariano

    Neil Benn Guest

    Hello,

    One way that I have done this is to make a file with :

    <key>=<value>\n

    Then open the file and use the following list comprehension to get
    back a dict with the properties in it :

    objFile = file('MyConfigurationFile.conf')

    dctConfiguration = dict([(key.strip(), value.strip()) \
    for (key,value) in [line.split('=') \
    for line in objFile]])

    It's not as simple as Properties in Java but you could wrap it in a
    class to copy the Java Properties class. You could also add some
    intellegence to it so that it doesn't bomb out if the properties file is
    slightly wrong.

    Cheers,

    Neil

    Mariano wrote:

    >Hi
    >
    >Have someone any idea how create/read a property file as java property file?
    >If not, is there some other solutions?
    >
    >Thank's in advance
    >
    >



    --

    Neil Benn
    Senior Automation Engineer
    Cenix BioScience
    BioInnovations Zentrum
    Tatzberg 47
    D-01307
    Dresden
    Germany

    Tel : +49 (0)351 4173 154
    e-mail :
    Cenix Website : http://www.cenix-bioscience.com
    Neil Benn, Jun 11, 2004
    #2
    1. Advertising

  3. Mariano

    Larry Bates Guest

    I would use ConfigParser from the standard library.
    It supports sections, built in conversions, default
    values, variable insertion, and writing of the
    file (as well as reading).

    -Larry Bates

    "Neil Benn" <> wrote in message
    news:...
    > Hello,
    >
    > One way that I have done this is to make a file with :
    >
    > <key>=<value>\n
    >
    > Then open the file and use the following list comprehension to get
    > back a dict with the properties in it :
    >
    > objFile = file('MyConfigurationFile.conf')
    >
    > dctConfiguration = dict([(key.strip(), value.strip()) \
    > for (key,value) in [line.split('=') \
    > for line in objFile]])
    >
    > It's not as simple as Properties in Java but you could wrap it in a
    > class to copy the Java Properties class. You could also add some
    > intellegence to it so that it doesn't bomb out if the properties file is
    > slightly wrong.
    >
    > Cheers,
    >
    > Neil
    >
    > Mariano wrote:
    >
    > >Hi
    > >
    > >Have someone any idea how create/read a property file as java property

    file?
    > >If not, is there some other solutions?
    > >
    > >Thank's in advance
    > >
    > >

    >
    >
    > --
    >
    > Neil Benn
    > Senior Automation Engineer
    > Cenix BioScience
    > BioInnovations Zentrum
    > Tatzberg 47
    > D-01307
    > Dresden
    > Germany
    >
    > Tel : +49 (0)351 4173 154
    > e-mail :
    > Cenix Website : http://www.cenix-bioscience.com
    >
    >
    Larry Bates, Jun 11, 2004
    #3
  4. Mariano

    Mariano Guest

    "Larry Bates" <> wrote in message news:<>...
    > I would use ConfigParser from the standard library.
    > It supports sections, built in conversions, default
    > values, variable insertion, and writing of the
    > file (as well as reading).
    >
    > -Larry Bates
    >
    > "Neil Benn" <> wrote in message
    > news:...
    > > Hello,
    > >
    > > One way that I have done this is to make a file with :
    > >
    > > <key>=<value>\n
    > >
    > > Then open the file and use the following list comprehension to get
    > > back a dict with the properties in it :
    > >
    > > objFile = file('MyConfigurationFile.conf')
    > >
    > > dctConfiguration = dict([(key.strip(), value.strip()) \
    > > for (key,value) in [line.split('=') \
    > > for line in objFile]])
    > >
    > > It's not as simple as Properties in Java but you could wrap it in a
    > > class to copy the Java Properties class. You could also add some
    > > intellegence to it so that it doesn't bomb out if the properties file is
    > > slightly wrong.
    > >
    > > Cheers,
    > >
    > > Neil
    > >
    > > Mariano wrote:
    > >
    > > >Hi
    > > >
    > > >Have someone any idea how create/read a property file as java property

    > file?
    > > >If not, is there some other solutions?
    > > >
    > > >Thank's in advance
    > > >
    > > >

    > >
    > >
    > > --
    > >
    > > Neil Benn
    > > Senior Automation Engineer
    > > Cenix BioScience
    > > BioInnovations Zentrum
    > > Tatzberg 47
    > > D-01307
    > > Dresden
    > > Germany
    > >
    > > Tel : +49 (0)351 4173 154
    > > e-mail :
    > > Cenix Website : http://www.cenix-bioscience.com
    > >
    > >



    I've found a great solutions!
    I use the ConfigParser, as Larry Bates says, because the manual parser
    with the character "=" isn't good.
    I can have this possible problem:
    Userkey = dklf343=S234978

    In this case, i would not simple problem.
    Instead, the ConfigParser is simple and affidable, with the sections!

    Thank's a lot at all!!!
    Mariano, Jun 15, 2004
    #4
    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. Eric Newton
    Replies:
    3
    Views:
    9,353
    Brock Allen
    Apr 4, 2005
  2. Joshua Beall
    Replies:
    1
    Views:
    411
    Bertilo Wennergren
    Dec 10, 2003
  3. Noozer
    Replies:
    10
    Views:
    2,038
    Mitja
    Oct 13, 2004
  4. Nathan Sokalski
    Replies:
    1
    Views:
    1,097
    =?Utf-8?B?SmVk?=
    Apr 29, 2006
  5. Dev_SH
    Replies:
    0
    Views:
    647
    Dev_SH
    Dec 30, 2010
Loading...

Share This Page