help in xml and python

K

Kirt

i have a List

modifiedfiles= [['/home/moq/buc/2/mod2.py', '200607131001'],
['/home/moq/buc/1/mod2.py', '200607131000'],
['/home/moq/buc/1/mod3.py', '200607131001'],
['/home/moq/buc/1+mod1.py', '200607131001']]

i have to put them in am xml format like the follg.

<modified>
<directory>
<dirname>/home/moq/buc/2</dirname>
<file>
<name>mod2.py</name>
<time>200607131001</time>
</file>
</directory>
<directory>
<dirname>/home/moq/buc/1</dirname>
<file>
<name>mod1.py</name>
<time>200607131001</time>
</file>
<file>
<name>mod2.py</name>
<time>200607131001</time>
</file>
<file>
<name>mod3.py</name>
<time>200607131001</time>
</file>
</directory>
</modified>


can someone please with the code for this.
 
F

Fredrik Lundh

Kirt said:
i have a List

modifiedfiles= [['/home/moq/buc/2/mod2.py', '200607131001'],
['/home/moq/buc/1/mod2.py', '200607131000'],
['/home/moq/buc/1/mod3.py', '200607131001'],
['/home/moq/buc/1+mod1.py', '200607131001']]

i have to put them in am xml format like the follg.
what i want to do :

i have entries, in a list format :[[key1,value],[key2,value],[
key3,value]], value]

example :
[["route","23"],["equip","jr2"],["time","3pm"]],"my first value"]
[["route","23"],["equip","jr1"],["time","3pm"]],"my second value"]
[["route","23"],["equip","jr2"],["time","3pm"]],"my third value"]
[["route","24"],["equip","jr2"],["time","3pm"]],"my fourth value"]
[["route","25"],["equip","jr2"],["time","3pm"]],'"my fifth value"]

the [XML] tree i want in the end would be :

which looks rather similar to your post, don't you think? check that thread
for some ideas:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/c3b3b6cf3613d7b3

</F>
 
M

Maric Michaud

Le jeudi 13 juillet 2006 12:50, Kirt a écrit :
   <directory>
    <dirname>/home/moq/buc/2</dirname>
    <file>
     <name>mod2.py</name>
     <time>200607131001</time>
    </file>
   </directory>

In [109]: xmldir = """ <directory>
.....: <dirname>%(dir)s</dirname>
.....: <file>
.....: <name>%(file)s</name>
.....: <time>%(time)s</time>
.....: </file>
.....: </directory>"""


In [116]: xmloutput = '\n'.join(('<modified>',) + tuple(xmldir % {'dir':
path.rsplit('/', 1)[0], 'file':path.split('/')[-1], 'time':time} for path,
time in modifiedfiles) + ('</modified>',)) #turning this into a readable not
one-liner code is left as an exercise :)

In [117]: print xmloutput
<modified>
<directory>
<dirname>/home/moq/buc/2</dirname>
<file>
<name>mod2.py</name>
<time>200607131001</time>
</file>
</directory>
<directory>
<dirname>/home/moq/buc/1</dirname>
<file>
<name>mod2.py</name>
<time>200607131000</time>
</file>
</directory>
<directory>
<dirname>/home/moq/buc/1</dirname>
<file>
<name>mod3.py</name>
<time>200607131001</time>
</file>
</directory>
<directory>
<dirname>/home/moq/buc</dirname>
<file>
<name>1+mod1.py</name>
<time>200607131001</time>
</file>
</directory>
</modified>


--
_____________

Maric Michaud
_____________

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
 
D

Diez B. Roggisch

can someone please with the code for this.

Show us your efforts, and we'd be glad to help you correcting/enhancing
them.

Or use PayPal and pay one of the guys here - my hourly fee is 50€, and
less than one hour work can't be booked.

Diez
 
S

Stefan Behnel

Diez said:
Or use PayPal and pay one of the guys here - my hourly fee is 50€, and
less than one hour work can't be booked.

He!

Don't tell people in public that you're working at 50€/hour! That's gonna
destruct the market. It's better if they believe there's nothing below 80€,
then they're more likely to ask for the people who know their real value.

Stefan
 
D

Dennis Lee Bieber

He!

Don't tell people in public that you're working at 50€/hour! That's gonna
destruct the market. It's better if they believe there's nothing below 80€,
then they're more likely to ask for the people who know their real value.

Maybe that was just the net (pre-tax) pay to him, and the client is
expected to cover medical, retirement, and workplace costs...

--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
J

John Draper

Diez said:
Show us your efforts, and we'd be glad to help you correcting/enhancing
them.

Or use PayPal and pay one of the guys here - my hourly fee is 50€, and
less than one hour work can't be booked.

Diez
I remember a few years ago, I posted something like this to the list,
and got flamed 6 ways from Sunday for having the audacity to propose
this. 50 Euros/hour is a very good rate by the way.. if more consultants
would offer their services this inexpensively, then perhaps it might even
be competitive with outsourcing.

John
 
F

Fredrik Lundh

John said:
I remember a few years ago, I posted something like this to the list,
and got flamed 6 ways from Sunday for having the audacity to propose
this.

certain people think that the mere thought of getting paid for
contributing to freely available software is outrageously immoral...
> 50 Euros/hour is a very good rate by the way.. if more consultants
would offer their services this inexpensively, then perhaps it might even
be competitive with outsourcing.

not sure about that, though: increasingly, outsourcing means paying
someone to sign up for a hotmail account and keep sending increasingly
annoying mails to fredrik lundh until he gives up and points to some
ready-made code that might solve the customer's problem (if I had a
dollar for every such mail etc etc).

</F>
 
P

Paul Boddie

Fredrik said:
not very long ago, "Kepioo" wrote:
[...]

which looks rather similar to your post, don't you think?

Are you calling "homework assignment", Fredrik? ;-)

Paul
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top