I have created a xml file using xml.etree.ElementTree in python. I then use to write out the document to a file. But when I open filename using a text editor, there are no newlines between the tags. Everything is one big line How can I write out the document in a “pretty printed” format so that there are new lines
How slow is Python’s string concatenation vs. str.join?
As a result of the comments in my answer on this thread, I wanted to know what the speed difference is between the += operator and ”.join() So what is the speed comparison between the two? Answer From: Efficient String Concatenation Method 1: Method 4: Now I realise they are not strictly representative, and the 4th method appends to a
What is the path that Django uses for locating and loading templates?
I’m following this tutorial on a Windows 7 environment. My settings file has this definition: I got the base_template from the template admin/base_site.html from within the default Django admin template directory in the source code of Django itself (django/contrib/admin/templates) into an admin subdirectory of myapp directory as the tutorial instructed, but it doesn’t seem to take affect for some reason.
Matrix in python
I am very new to Python, I need to read numbers from a file and store them in a matrix like I would do it in fortran or C; How can I do the same in Python? I read a bit but got confused with tuples and similar things If you could point me to a similar example it would
Which os is better for development : Debian or Ubuntu? [closed]
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 12 years ago.
How do I debug a HTTP 502 error?
I have a Python Tornado server sitting behind a nginx frontend. Every now and then, but not every time, I get a 502 error. I look in the nginx access log and I see this: and in the error log: I don’t think any errors show up in the Tornado log. How would you go about debugging this? Is there
Python – calendar.timegm() vs. time.mktime()
I seem to have a hard time getting my head around this. What’s the difference between calendar.timegm() and time.mktime()? Say I have a datetime.datetime with no tzinfo attached, shouldn’t the two give the same output? Don’t they both give the number of seconds between epoch and the date passed as a parameter? And since the date passed has no tzinfo,
built in function for computing overlap in Python
is there a built in function to compute the overlap between two discrete intervals, e.g. the overlap between [10, 15] and [20, 38]? In that case the overlap is 0. If it’s [10, 20], [15, 20], the overlap is 5. Answer You can use max and min:
Pinging servers in Python
In Python, is there a way to ping a server through ICMP and return TRUE if the server responds, or FALSE if there is no response? Answer This function works in any OS (Unix, Linux, macOS, and Windows) Python 2 and Python 3 EDITS: By @radato os.system was replaced by subprocess.call. This avoids shell injection vulnerability in cases where your
Kill process by name?
I’m trying to kill a process (specifically iChat). On the command line, I use these commands: Then: However, I’m not exactly sure how to translate these commands over to Python. Answer Assuming you’re on a Unix-like platform (so that ps -A exists), gives you ps -A’s output in the out variable (a string). You can break it down into lines