I have an XML file with several thousand records in it in the form of: How can I convert this into a CSV or tab-delimited file? I know I can hard-code it in Python using re.compile() statements, but there has to be something easier, and more portable among diff XML file layouts. I’ve found a couple threads here about attribs,
Tag: python-3.x
Python: How can I calculate the average word length in a sentence using the .split command?
new to python here. I am trying to write a program that calculate the average word length in a sentence and I have to do it using the .split command. btw im using python 3.2 this is what I’ve wrote so far So far i have the user enter a sentence and it successfully splits each individual word they enter,
Overriding in Python
I want to be able to do the following I would like to get a parent function from a child class in a function that is overriding it. I am not sure how to do this. This is a little hard to explain, comment if you are having trouble understanding. Edit: Thanks for the answers everyone, I almost thought that
Generate list of numbers in specific format
I need to generate a list of numbers in a specific format. The format is I know how to generate a normal list of numbers using range So, is there any built-in way in python to generate a list of numbers in the specified format. Answer Python string formatting allows you to specify a precision: Precision (optional), given as a
Validate Postal Code?
I’m doing some tutorials online…and I’m stuck at an exercise:Define a function postalValidate(S) which first checks if S represents a postal code which is valid. Note: I’m supposed to solve it with strings, lists, if statements, loops, and other basic constructs like variables and functions. first, delete all spaces; the remainder must be of the form L#L#L# where L are
What’s the difference between __builtin__ and __builtins__?
I was coding today and noticed something. If I open a new interpreter session (IDLE) and check what’s defined with the dir function I get this: Please note the last line. So, my question is: Is any an alias of the other one? Are the Python guys planning to get rid of one of those? What should I use for
Replacing a word in a text file with a value using python
I have been trying to replace a word in a text file with a value (say 1), but my outfile is blank.I am new to python (its only been a month since I have been learning it). My file is relatively large, but I just want to replace a word with the value 1 for now. Here is a segment
Looking for a better python Google Calendar API example
I am trying to write an application that can add events to a google calendar. There is this really neat site that lets you play with the API. http://code.google.com/apis/explorer/#_s=calendar&_v=v3&_m=events.insert Using that site, I was able to build a calendar event using the following stuff. I am having difficulty translating that into python. Assuming that I’ve already authenticated with oauth, How
Can I get an item from a PriorityQueue without removing it yet?
I want to get the next item in queue but I don’t want to dequeue it. Is it possible in Python’s queue.PriorityQueue? From the docs, I don’t see how can it be done Answer When you get item form the queue as per theory it will remove from the queue. You have to write your own function which will give
custom dict that allows delete during iteration
UPDATED based on Lennart Regebro’s answer Suppose you iterate through a dictionary, and sometimes need to delete an element. The following is very efficient: The only overhead here is building the list of keys to remove; unless it grows large compared to the dictionary size, it’s not an issue. However, this approach requires some extra coding, so it’s not very