ich möchte ein Verzeichnispfad in einer Konfigdatei hinterlegen. Das habe ich wie folgt gemacht:
config.cfg
Code: Alles auswählen
[Connection]
user: "user"
password: "xxxxxxxxx"
balancer_url: "http://<ip>/bla"
hosts_a: "C:\Users\gegu\PycharmProjects\balancingTomcats\hosts_a.xml"
hosts_b: "C:\Users\gegu\PycharmProjects\balancingTomcats\hosts_b.xml"
Code: Alles auswählen
def choose_environment(env_input):
if env_input not in env_list:
sys.stderr.write("Diese Umgebung {0} gibt es nicht".format(env_input))
sys.stderr.flush()
return 2
else:
if env_input == "a":
xml_doc=read_config()["hosts_a"]
else:
xml_doc=read_config()["hosts_b"]
return xml_doc
Code: Alles auswählen
def read_config():
config = ConfigParser.ConfigParser()
config.read(config_file)
dict1 = {}
options = config.options("Connection")
for option in options:
try:
dict1[option] = config.get("Connection", option)
if dict1[option] == -1:
print "skip: %s" % option
except:
print "exception on %s!" % option
dict1[option] = None
return dict1
Code: Alles auswählen
C:\\Users\\gegu\\PycharmProjects\\balancingTomcats\\hosts_b.xml
Code: Alles auswählen
C:\\\\Users\\\\gegu\\\\PycharmProjects\\\\balancingTomcats\\hosts_b.xml
Ich weiß nicht warum aber die Codebox mit Python-Syntaxhighligt hat nicht funktioniert. Deswegen habe ich die Quellcodes als Standart-Code gepostet.
Vielen Dank für die Hilfe
VG niesel