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
Tag: python
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 starte…
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 proce…
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 r…
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 longe…
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 distrib…
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…
A more suitable way to rewrite this?
I have the method: This just returns the first of the month 2 months ago, which is what I want is there a better approach I could have used using timedeltas? I choose my way because weeks in a month are not always constant. Answer dateutil is an amazing thing. It really should become stdlib someday.
A simple Python HTTP proxy [closed]
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations. Closed 4 years ago. The community rev…