Deepak Deepak - 11 months ago 58
Python Question

Why the value read from properties file in python doesn't work

I am brand new to Python. I have some python script which is accessed by other project to read some data from this python script.

If suppose I need to provide the version information for the other project from this python script, I was having a class variable which was hard coded and it was working fine till now.

I wanted to change the way of providing the version information so I choose to read the properties file instead of hard coding. I have added these line in my script

previously it was just this line

class Myclass
version = '1.2'

Now I changed it to

class Myclass
config = ConfigParser.RawConfigParser()'')
version = config.get('global', 'version')
print version

my file looks like

version= 1.2

when I run this python file to print the version, it is clearly printing in the console. But when this variable is being accessed by that other project the version read from the properties file is not being read (Hard coded value works just fine).

What could be the difference? Why is the value read from properties file is not reflecting?

Answer Source

If the file will be in the same directory as your code, you can use this:

import os, ''))