Question

I'm fairly new to Python, and I'm looking to do some basic things with PyYAML. What I want to do is take a YAML file:

#Lets test out the logfile config
---
filepath: C:\Users\Me\Documents\Python\yaml_test1\ 
filename: logfile_
log_no: 1

Now basically what I'm shooting for is a way to control a path to a logfile, the root name of the log, and what number log we're on which is appended to filename (to rollover to a new log when we hit a certain KB file size).

import yaml
import os

rootDir = os.getcwd()
c_FileName = rootDir + "\\config.yml"
c_FileIn = open(c_FileName,'r+')
conf = yaml.load(c_FileIn)
a = conf['log_no']
a += 1
print a
conf['log_no'] = a
print yaml.dump(conf['log_no'])
yaml.dump(conf,c_FileIn)
c_FileIn.close()

My problem is that dumping to the file just dumps the full (though updated) yaml file, but at the end of the config. Any suggestions?

Ninja edit: I'm open to any and all suggestions, even it it's to use something other than yaml. It was just something I was reading into and wanted to give a shot.

Was it helpful?

Solution

So I'm going to close this since I have found the ConfigParser module that does exactly what I was looking for with the rotating logfile

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top