Firstly: sorry about my pathetic english language skill.
Secondly: i have learnt python for few weeks, so please be patient.:)
My project:
I got a directory with multiple files (xml).
they looks like:
thingy1_442354565666.xml
thingy2_502354565666.xml
thingy3_692354565666.xml
etc.
The numbers in filename represent the files last modification date. The bigger number means recent files. (This will be important later.)
Each xml contains two element.
for example:
<period>012012</period> # this represent months
<charges>1098</charges> # EUR
The problem:
I need an output txt with from each month.
like this:
jan: 1098
feb: 499
etc.
Unfortunately I have more than 12 xml in that directory, so i got 2-3 files (I always need the last modified file) in each months.
I tried to make a dictionary with filenames and period element, but i totaly lost.
Btw i can parse xml with elementtree etc., but i dont know how to choose the last modified file from each month.
Please help me out, and ask if i was not understandable.
Thanks!
If larger numbers mean older files, sort the file list and iterate the files from smallest to largest (i.e. newest files first).
Parse the xml and keep track of the
(year, month)pairs you have seen. If you have already seen a pair, then you have already processed the newest file for that month and you can ignore subsequent files.Something like:
Usage: