Proper use of mutexes in Python

I don’t know why you’re using the Window’s Mutex instead of Python’s. Using the Python methods, this is pretty simple: But note, because of the architecture of CPython (namely the Global Interpreter Lock) you’ll effectively only have one thread running at a time anyway–this is fine if a number of them are I/O bound, although … Read more

Convert hex string to int in Python

Without the 0x prefix, you need to specify the base explicitly, otherwise there’s no way to tell: With the 0x prefix, Python can distinguish hex and decimal automatically. (You must specify 0 as the base in order to invoke this prefix-guessing behavior; if you omit the second parameter int() will assume base-10.)

BeautifulSoup getting href

I have the following soup: From this I want to extract the href, “some_url” I can do it if I only have one tag, but here there are two tags. I can also get the text ‘next’ but that’s not what I want. Also, is there a good description of the API somewhere with examples. … Read more

How do you read a file into a list in Python?

I want to prompt a user for a number of random numbers to be generated and saved to a file. He gave us that part. The part we have to do is to open that file, convert the numbers into a list, then find the mean, standard deviation, etc. without using the easy built-in Python … Read more

Is there any way to kill a Thread?

It is generally a bad pattern to kill a thread abruptly, in Python, and in any language. Think of the following cases: the thread is holding a critical resource that must be closed properly the thread has created several other threads that must be killed as well. The nice way of handling this, if you … Read more