Discussion:
[Tutor] Newbie to Python: enumerate XML tags (keys that will become headers) along with text (values) and write to CSV in one row (as opposed to "stacked" values with one header)
Saran Ahluwalia
2015-06-25 18:42:16 UTC
Permalink
My question can be found here:


http://stackoverflow.com/questions/31058100/enumerate-column-headers-in-csv-that-belong-to-the-same-tag-key-in-python


Here is an additional sample sample of the XML that I am working with:

<Response ID="123546 - 7831" RequestType="Moverview">
<MonthDayCount>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
</MonthDayCount>
<FeeCount>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
</FeeCount>
<PaymentBucketAmount>
<Double>0</Double>
<Double>0</Double>
<Double>0</Double>
<Double>0</Double>
<Double>0</Double>
<Double>0</Double>
<Double>0</Double>
<Double>0</Double>
</PaymentBucketAmount>
<PaymentBucketDueDate>
<DateTime>1/1/0001 12:00:00 AM</DateTime>
<DateTime>1/1/0001 12:00:00 AM</DateTime>
<DateTime>1/1/0001 12:00:00 AM</DateTime>
<DateTime>1/1/0001 12:00:00 AM</DateTime>
<DateTime>1/1/0001 12:00:00 AM</DateTime>
<DateTime>1/1/0001 12:00:00 AM</DateTime>
<DateTime>1/1/0001 12:00:00 AM</DateTime>
<DateTime>1/1/0001 12:00:00 AM</DateTime>
</PaymentBucketDueDate>
<Warnings />
<SList />
<LList />
<PA>False</PA>
<PL>False</PL>
<PC>False</PC>
<PCs>False</PCs>
<PJ>False</PJ>
<OITC>0</OITC>
<MG />
<R />
<CCGoods />
</Response>
Alan Gauld
2015-06-25 22:51:16 UTC
Permalink
Post by Saran Ahluwalia
http://stackoverflow.com/questions/31058100/enumerate-column-headers-in-csv-that-belong-to-the-same-tag-key-in-python
It would have been helpful to post the question here rather than just a
link.

However, having read it, I'm still not sure what you want to do?
It seems your input file (the XML one?) has multiple ObjectGuid tags?
And you want to write them out to a CSV file with a number appended
(objectGuid_1, ObjectGuid_2 etc) Is that right? If so what exactly is
the issue - it seems simple enough (given your obvious coding
experience) to store a counter and create a new string each time you
find a GUID tag?

But I still don't understand how these tags relate to the rest of the
data in the file? Are you only extracting the GUID and want one row per
file? Or are you extracting multiple data structures and creating a row
for each? In which case are the multiple GUID embedded in each data
structure? I'm really not sure what you are trying to do.
I have no idea how that is supposed to help? It doesn't have any
ObjectGUID tags that I can see? It is essentially meaningless
data (to us).
Post by Saran Ahluwalia
<Response ID="123546 - 7831" RequestType="Moverview">
<MonthDayCount>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
</MonthDayCount>
<FeeCount>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
<Int32>0</Int32>
</FeeCount>
<PaymentBucketAmount>
<Double>0</Double>
<Double>0</Double>
<Double>0</Double>
<Double>0</Double>
<Double>0</Double>
<Double>0</Double>
<Double>0</Double>
<Double>0</Double>
</PaymentBucketAmount>
<PaymentBucketDueDate>
<DateTime>1/1/0001 12:00:00 AM</DateTime>
<DateTime>1/1/0001 12:00:00 AM</DateTime>
<DateTime>1/1/0001 12:00:00 AM</DateTime>
<DateTime>1/1/0001 12:00:00 AM</DateTime>
<DateTime>1/1/0001 12:00:00 AM</DateTime>
<DateTime>1/1/0001 12:00:00 AM</DateTime>
<DateTime>1/1/0001 12:00:00 AM</DateTime>
<DateTime>1/1/0001 12:00:00 AM</DateTime>
</PaymentBucketDueDate>
<Warnings />
<SList />
<LList />
<PA>False</PA>
<PL>False</PL>
<PC>False</PC>
<PCs>False</PCs>
<PJ>False</PJ>
<OITC>0</OITC>
<MG />
<R />
<CCGoods />
</Response>
--
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Mark Lawrence
2015-06-26 00:36:02 UTC
Permalink
Post by Alan Gauld
Post by Saran Ahluwalia
http://stackoverflow.com/questions/31058100/enumerate-column-headers-in-csv-that-belong-to-the-same-tag-key-in-python
It would have been helpful to post the question here rather than just a
link.
However, having read it, I'm still not sure what you want to do?
It seems your input file (the XML one?) has multiple ObjectGuid tags?
And you want to write them out to a CSV file with a number appended
(objectGuid_1, ObjectGuid_2 etc) Is that right? If so what exactly is
the issue - it seems simple enough (given your obvious coding
experience) to store a counter and create a new string each time you
find a GUID tag?
But I still don't understand how these tags relate to the rest of the
data in the file? Are you only extracting the GUID and want one row per
file? Or are you extracting multiple data structures and creating a row
for each? In which case are the multiple GUID embedded in each data
structure? I'm really not sure what you are trying to do.
I have no idea how that is supposed to help? It doesn't have any
ObjectGUID tags that I can see? It is essentially meaningless
data (to us).
I wouldn't be inclined to put too much into this, it's already been
asked on the main mailing list and appears to be a follow up to an
earlier thread.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Steven D'Aprano
2015-06-26 15:23:20 UTC
Permalink
Post by Saran Ahluwalia
http://stackoverflow.com/questions/31058100/enumerate-column-headers-in-csv-that-belong-to-the-same-tag-key-in-python
You might think you are saving time in not typing the question twice,
but you're not. You're just limiting the number of people who might
answer your question, which means it will take you even longer to get
the answer. The 30 seconds that you save by not writing the question
here might cost you hours or days to get an answer.

I'm reading your question via email, and it is inconvenient for me to
switch to a browser and go read the question on another site, copy the
question, paste it back into an email, manually edit that to quote it
(add > to the beginning of each line), and then respond. If I really
cared about your question, if it was a topic that interested me greatly,
I might do it. But I don't like dealing with XML and I think CSV is
boring, so I won't.

Other tutors might be browsing their email from a network that blocks
Stackoverflow, so they cannot see the question at all.
--
Steve
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Loading...