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 subdirec…
Tag: python
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, …
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 pas…
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 injectio…
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 v…
Letter Count on a string
Python newb here. I m trying to count the number of letter “a”s in a given string. Code is below. It keeps returning 1 instead 3 in string “banana”. Any input appreciated. Answer The other answers show what’s wrong with your code. But there’s also a built-in way to do this,…
What do the * (star) and ** (double star) operators mean in a function call?
In code like zip(*x) or f(**k), what do the * and ** respectively mean? How does Python implement that behaviour, and what are the performance implications? See also: Expanding tuples into arguments. Please use that one to close questions where OP needs to use * on an argument and doesn’t know it exists…