Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > property file

Reply
Thread Tools

property file

 
 
Mariano
Guest
Posts: n/a
 
      06-11-2004
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
 
Reply With Quote
 
 
 
 
Neil Benn
Guest
Posts: n/a
 
      06-11-2004
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 : http://www.velocityreviews.com/forums/(E-Mail Removed)
Cenix Website : http://www.cenix-bioscience.com


 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      06-11-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 : (E-Mail Removed)
> Cenix Website : http://www.cenix-bioscience.com
>
>



 
Reply With Quote
 
Mariano
Guest
Posts: n/a
 
      06-15-2004
"Larry Bates" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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 : (E-Mail Removed)
> > 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!!!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Property File - property value break on multiple line Dev_SH Java 0 12-30-2010 09:34 AM
TableCell: BackColor Property But No BackGround Property? Nathan Sokalski ASP .Net 1 04-29-2006 10:09 PM
DataBinder.Eval for an object's property property... like Eval(Container.DataItem,"Version.Major") Eric Newton ASP .Net 3 04-04-2005 10:11 PM
Set CSS property equal to another CSS property? Noozer HTML 10 10-13-2004 09:20 PM
Is there a way to set the a CSS property to be explicitly the same as another CSS property? Joshua Beall HTML 1 12-10-2003 07:21 PM



Advertisments