Most Popular
1500 questions
1192
votes
6 answers
Create Git branch with current changes
I started working on my master branch thinking that my task would be easy. After a while I realized it would take more work and I want to do all this work in a new branch.
How can I create a new branch and take all these changes with me without…

willcodejavaforfood
- 43,223
- 17
- 81
- 111
1192
votes
13 answers
What are "named tuples" in Python?
What are named tuples and how do I use them?
When should I use named tuples instead of normal tuples, or vice versa?
Are there "named lists" too? (i.e. mutable named tuples)
For the last question specifically, see also Existence of mutable named…

Denilson Sá Maia
- 47,466
- 33
- 109
- 111
1192
votes
3 answers
How are zlib, gzip and zip related? What do they have in common and how are they different?
The compression algorithm used in zlib is essentially the same as that in gzip and zip. What are gzip and zip? How are they different and how are they same?

Abhishek Jain
- 9,614
- 5
- 26
- 40
1192
votes
15 answers
Difference between del, remove, and pop on lists
Is there any difference between these three methods to remove an element from a list?
a = [1, 2, 3]
a.remove(2)
a # [1, 3]
a = [1, 2, 3]
del a[1]
a # [1, 3]
a = [1, 2, 3]
a.pop(1) # 2
a # [1, 3]

sachin irukula
- 12,841
- 4
- 19
- 19
1191
votes
12 answers
Remove a symlink to a directory
I have a symlink to an important directory. I want to get rid of that symlink, while keeping the directory behind it.
I tried rm and get back rm: cannot remove 'foo'.
I tried rmdir and got back rmdir: failed to remove 'foo': Directory not empty
I…

Matthew Scouten
- 15,303
- 9
- 33
- 50
1190
votes
34 answers
Android "Only the original thread that created a view hierarchy can touch its views."
I've built a simple music player in Android. The view for each song contains a SeekBar, implemented like this:
public class Song extends Activity implements OnClickListener,Runnable {
private SeekBar progress;
private MediaPlayer mp;
…

herpderp
- 15,819
- 12
- 42
- 45
1190
votes
19 answers
How do you test that a Python function throws an exception?
How does one write a unit test that fails only if a function doesn't throw an expected exception?

Daryl Spitzer
- 143,156
- 76
- 154
- 173
1189
votes
17 answers
What's the difference between HEAD^ and HEAD~ in Git?
When I specify an ancestor commit object in Git, I'm confused between HEAD^ and HEAD~.
Both have a "numbered" version like HEAD^3 and HEAD~2.
They seem very similar or the same to me, but are there any differences between the tilde and the caret?

TK.
- 27,073
- 20
- 64
- 72
1188
votes
9 answers
How do I type hint a method with the type of the enclosing class?
I have the following code in Python 3:
class Position:
def __init__(self, x: int, y: int):
self.x = x
self.y = y
def __add__(self, other: Position) -> Position:
return Position(self.x + other.x, self.y +…

Michael van Gerwen
- 12,011
- 3
- 11
- 8
1187
votes
34 answers
How do I remove all packages installed by pip?
How do I uninstall all packages installed by pip from my currently activated virtual environment?

blueberryfields
- 45,910
- 28
- 89
- 168
1185
votes
37 answers
findViewById in Fragment
I am trying to create an ImageView in a Fragment which will refer to the ImageView element which I have created in the XML for the Fragment. However, the findViewById method only works if I extend an Activity class. Is there anyway of which I can…

simplified.
- 11,977
- 5
- 17
- 8
1185
votes
8 answers
How to create a GUID/UUID in Python
How do I create a GUID/UUID in Python that is platform independent? I hear there is a method using ActivePython on Windows but it's Windows only because it uses COM. Is there a method using plain Python?

Jonathon Watney
- 20,248
- 9
- 38
- 40
1185
votes
14 answers
Usage of __slots__?
What is the purpose of __slots__ in Python — especially with respect to when I would want to use it, and when not?

Jeb
- 15,939
- 6
- 34
- 37
1185
votes
30 answers
Get unique values from a list in python
I want to get the unique values from the following list:
['nowplaying', 'PBS', 'PBS', 'nowplaying', 'job', 'debate', 'thenandnow']
The output which I require is:
['nowplaying', 'PBS', 'job', 'debate', 'thenandnow']
This code works:
output = []
for…

savitha
- 12,131
- 4
- 19
- 13
1184
votes
11 answers
Maximum and Minimum values for ints
How do I represent minimum and maximum values for integers in Python? In Java, we have Integer.MIN_VALUE and Integer.MAX_VALUE.
See also: What is the maximum float in Python?.

bdhar
- 21,619
- 17
- 70
- 86