property file

M

Mariano

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
 
N

Neil Benn

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
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 address removed)
Cenix Website : http://www.cenix-bioscience.com
 
L

Larry Bates

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 said:
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
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 address removed)
Cenix Website : http://www.cenix-bioscience.com
 
M

Mariano

Larry Bates said:
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 said:
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
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 address 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!!!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top