I’m trying to run an Icecast stream using a simple Python script to pick a random song from the list of songs on the server. I’m looking to add a voting/request interface, and my host allows use of python to serve webpages through CGI. However, I’m getting hung up on just how to get the GET arguments supplied by the
Python Regular Expression Match All 5 Digit Numbers but None Larger
I’m attempting to string match 5-digit coupon codes spread throughout a HTML web page. For example, 53232, 21032, 40021 etc… I can handle the simpler case of any string of 5 digits with [0-9]{5}, though this also matches 6, 7, 8… n digit numbers. Can someone please suggest how I would modify this regular expression to match only 5 digit
Is there a way to iterate a specified number of times without introducing an unnecessary variable?
If I want to iterate n times in Java, I write: In Python, it seems the standard way to do this is: As always, Python is more concise and more readable. But the x bothers me, as it is unnecessary, and PyDev generates a warning, since x is never used. Is there a way to do this that doesn’t generate
How do I know what python scripts are running in Windows?
As I mentioned above, is there a way to find out what python scripts are running in Windows? Answer If you have PowerShell installed, you can get that information by using Windows Management Instrumentation (WMI) and some scripting… Open the PowerShell and use these two lines, it should could you started: This will show you the command line arguments used
Run Process and Don’t Wait
I’d like to run a process and not wait for it to return. I’ve tried spawn with P_NOWAIT and subprocess like this: However, the console window remains until I close Notepad. Is it possible to launch the process and not wait for it to complete? Answer This call doesn’t wait for the child process to terminate (on Linux). Don’t ask
How to completely remove Python from a Windows machine?
I installed both Python 2.7 and Python 2.6.5. I don’t know what went wrong, but nothing related to Python seems to work any more. e.g. “setup.py install” for certain packages don’t recognize the “install” parameter and other odd phenomena… I would like to completely remove Python from my system. I tried running the 2.7 and 2.6 msi files and choosing
Pythonic way to split a list into first and rest in Python 2.x?
I think in Python 3 I’ll be able to do: which is exactly what I want, but I’m using 2.6. For now I’m doing: This is fine, but I was just wondering if there’s something more elegant. Answer Basically the same, except that it’s a oneliner. Tuple assigment rocks. This is a bit longer and less obvious, but generalized for
Convert Z-score (Z-value, standard score) to p-value for normal distribution in Python
How does one convert a Z-score from the Z-distribution (standard normal distribution, Gaussian distribution) to a p-value? I have yet to find the magical function in Scipy’s stats module to do this, but one must be there. Answer I like the survival function (upper tail probability) of the normal distribution a bit better, because the function name is more informative:
How to sum dict elements
In Python, I have list of dicts: I want one final dict that will contain the sum of all dicts. I.e the result will be: {‘a’:5, ‘b’:7} N.B: every dict in the list will contain same number of key, value pairs. Answer A little ugly, but a one-liner:
How can I get a human-readable timezone name in Python?
In a Python project I’m working on, I’d like to be able to get a “human-readable” timezone name of the form America/New_York, corresponding to the system local timezone, to display to the user. Every piece of code I’ve seen that accesses timezone information only returns either a numeric offset (-0400) or a letter code (EDT) or sometimes both. Is there