Tag: python

63 votes
30 answers
992 views
How can I install pip on Windows?

pip is a replacement for easy_install. But should I install pip using easy_install on Windows? Is there a bett

avatar
Jeff
0 1 0 9
asked 07 September, 2021
55 votes
13 answers
559 views
How to delete a file or folder in Python?

How do I delete a file or folder in Python?

avatar
Boyd
0 1 0 9
asked 07 September, 2021
49 votes
10 answers
938 views
Manually raising (throwing) an exception in Python

How can I raise an exception in Python so that it can later be caught via an except block?

avatar
Royal
0 1 0 9
asked 07 September, 2021
53 votes
11 answers
1.3K views
How do I select rows from a DataFrame based on column values?

How can I select rows from a DataFrame based on values in some column in Pandas? In SQL, I would use: SELECT *

avatar
Freida
0 1 0 9
asked 07 September, 2021
58 votes
16 answers
503 views
55 votes
23 answers
867 views
What does ** (double star/asterisk) and * (star/asterisk) do for parameters?

In the following method definitions, what does the * and ** do for param2? def foo(param1, *param2): def bar(

avatar
Kristopher
0 1 0 9
asked 07 September, 2021
65 votes
7 answers
1.7K views
Understanding Python super() with __init__() methods

I'm trying to understand the use of super(). From the looks of it, both child classes can be created,

avatar
Nidia
0 1 0 9
asked 07 September, 2021
59 votes
12 answers
1.4K views
What is __init__.py for?

What is __init__.py for in a Python source directory?

avatar
Renaldo
0 1 0 9
asked 07 September, 2021
52 votes
22 answers
1.7K views
List changes unexpectedly after assignment. Why is this and how can I prevent it?

While using new_list = my_list, any modifications to new_list changes my_list every time. Why is this, and how

avatar
Elicia
0 1 0 9
asked 07 September, 2021
67 votes
17 answers
821 views
How to make function decorators and chain them together?

How can I make two decorators in Python that would do the following? @makebold @makeitalic def say(): retu

avatar
Shanita
0 1 0 9
asked 07 September, 2021
54 votes
29 answers
2.8K views
How to iterate over rows in a DataFrame in Pandas

I have a DataFrame from Pandas: import pandas as pd inp = [{'c1':10, 'c2':100}, {'c1

avatar
Frederick
0 1 0 9
asked 07 September, 2021
54 votes
30 answers
1.6K views
"Least Astonishment" and the Mutable Default Argument

Anyone tinkering with Python long enough has been bitten (or torn to pieces) by the following issue: def foo(a

avatar
Chaya
0 1 0 9
asked 07 September, 2021
59 votes
30 answers
1.4K views
How do I pass a variable by reference?

The Python documentation seems unclear about whether parameters are passed by reference or value, and the foll

avatar
Gigi
0 1 0 9
asked 07 September, 2021
60 votes
21 answers
495 views
Convert bytes to a string

I'm using this code to get standard output from an external program: >>> from subprocess import

avatar
Keith
0 1 0 9
asked 07 September, 2021
47 votes
19 answers
1.3K views
How do I copy a file in Python?

How do I copy a file in Python? I couldn't find anything under os.

avatar
Robt
0 1 0 9
asked 07 September, 2021
50 votes
29 answers
3K views
How do I concatenate two lists in Python?

How do I concatenate two lists in Python? Example: listone = [1, 2, 3] listtwo = [4, 5, 6] Expected outcom

avatar
Tana
0 1 0 9
asked 07 September, 2021
54 votes
20 answers
1.4K views
How can I add new keys to a dictionary?

Is it possible to add a key to a Python dictionary after it has been created? It doesn't seem to have an

avatar
Venice
0 1 0 9
asked 07 September, 2021
58 votes
25 answers
2.9K views
What is the difference between __str__ and __repr__?

What is the difference between __str__ and __repr__ in Python?

avatar
Nereida
0 1 0 9
asked 07 September, 2021
60 votes
27 answers
371 views
How do I check if a list is empty?

avatar
Lashawna
0 1 0 9
asked 07 September, 2021
61 votes
5 answers
2.4K views
Catch multiple exceptions in one line (except block)

I know that I can do: try: # do something that may fail except: # do this if ANYTHING goes wrong I

avatar
Chaya
0 1 0 9
asked 07 September, 2021