Most answered questions in Python

0 votes
1 answer

How do I copy a file in Python?

from shutil import copyfile copyfile(src, dst) Copy the contents ...READ MORE

Dec 7, 2020 in Python by Gitika
• 65,910 points
388 views
0 votes
1 answer

How do I remove/delete a folder that is not empty?

import shutil shutil.rmtree('/folder_name') By design, rmtree fails on folder trees containing ...READ MORE

Dec 7, 2020 in Python by Gitika
• 65,910 points
1,073 views
0 votes
1 answer

List changes unexpectedly after assignment. How do I clone or copy it to prevent this?

With new_list = my_list, you don't actually have ...READ MORE

Dec 7, 2020 in Python by Gitika
• 65,910 points
731 views
0 votes
1 answer

How to delete a file or folder?

os.remove() removes a file. os.rmdir() removes an empty directory. shutil.rmtree() deletes a ...READ MORE

Dec 7, 2020 in Python by Gitika
• 65,910 points
326 views
0 votes
1 answer

How do I copy a file in Python?

from shutil import copyfile copyfile(src, dst) Copy the ...READ MORE

Dec 7, 2020 in Python by Gitika
• 65,910 points
354 views
0 votes
1 answer

pip install mysql-python fails with EnvironmentError: mysql_config not found

It seems mysql_config is missing on your ...READ MORE

Dec 4, 2020 in Python by Gitika
• 65,910 points
1,307 views
0 votes
1 answer

How to install packages using pip according to the requirements.txt file from a local directory?

This works for me: $ pip install -r ...READ MORE

Dec 4, 2020 in Python by Gitika
• 65,910 points
5,242 views
0 votes
1 answer

How to find which version of package is installed with pip?

As of pip 1.3, there is a pip show command. $ ...READ MORE

Dec 4, 2020 in Python by Gitika
• 65,910 points
4,526 views
0 votes
1 answer

How to uninstall a package installed with pip install --user?

Having tested this using Python 3.5 and ...READ MORE

Dec 4, 2020 in Python by Gitika
• 65,910 points
16,878 views
0 votes
1 answer

What is the easiest way to remove all packages installed by pip?

I've found this snippet as an alternative ...READ MORE

Dec 4, 2020 in Python by Gitika
• 65,910 points
502 views
0 votes
1 answer

How to make function decorators and chain them together?

Here is what you asked for: from functools ...READ MORE

Dec 4, 2020 in Python by Gitika
• 65,910 points
424 views
0 votes
1 answer

Getting the last element of a list

some_list[-1] is the shortest and most Pythonic. In fact, ...READ MORE

Dec 3, 2020 in Python by anonymous
• 65,910 points
330 views
0 votes
1 answer

How to find the index of an item in a list?

One thing that is really helpful in ...READ MORE

Dec 3, 2020 in Python by Gitika
• 65,910 points
1,194 views
0 votes
1 answer

How do I concatenate two lists in Python?

You can use the + operator to combine them: listone ...READ MORE

Dec 3, 2020 in Python by anonymous
• 65,910 points
369 views
0 votes
1 answer

How do you split a list into evenly sized chunks?

Here's a generator that yields the chunks ...READ MORE

Dec 3, 2020 in Python by Gitika
• 65,910 points
760 views
0 votes
1 answer

Install a Python package into a different directory using pip?

Use: pip install --install-option="--prefix=$PREFIX_PATH" package_name You might also want ...READ MORE

Dec 3, 2020 in Python by Gitika
• 65,910 points
1,894 views
0 votes
1 answer

How to invoke a python static method inside class via string method name?

Use __import__ function to import the module by giving ...READ MORE

Dec 3, 2020 in Python by Gitika
• 65,910 points
955 views
0 votes
1 answer

How to invoke a function on an object dynamically by name?

Use "getattr":  obj = MyClass() try: ...READ MORE

Dec 3, 2020 in Python by Gitika
• 65,910 points
3,677 views
0 votes
1 answer

How do I check if a string is a number (float)?

I'm not sure that anything much could ...READ MORE

Dec 2, 2020 in Python by Gitika
• 65,910 points
567 views
0 votes
1 answer

How to determine a Python variable's type?

Use the type() builtin function: >>> i = 123 >>> type(i) <type ...READ MORE

Dec 2, 2020 in Python by Gitika
• 65,910 points
320 views
0 votes
1 answer

How to know if an object has an attribute in Python?

Try hasattr(): if hasattr(a, 'property'): a.property The ...READ MORE

Dec 2, 2020 in Python by Gitika
• 65,910 points
432 views
0 votes
1 answer

Static methods in Python?

Yep, using the static method decorator class MyClass(object): ...READ MORE

Dec 2, 2020 in Python by Gitika
• 65,910 points
391 views
0 votes
1 answer

Limiting floats to two decimal points?

You are running into the old problem with floating-point ...READ MORE

Dec 2, 2020 in Python by Gitika
• 65,910 points
3,255 views
0 votes
1 answer

Why is it string.join(list) instead of list.join(string)?

It's because any iterable can be joined ...READ MORE

Dec 2, 2020 in Python by Gitika
• 65,910 points
526 views
0 votes
1 answer

How to randomly select an item from a list?

Use random.choice() import random foo = ['a', 'b', 'c', 'd', ...READ MORE

Dec 2, 2020 in Python by Gitika
• 65,910 points
506 views
0 votes
1 answer

Webscraping error using your code

Hi, @Shrinidhi, Kindly share your code snippet with ...READ MORE

Dec 2, 2020 in Python by Gitika
• 65,910 points
444 views
0 votes
1 answer

python code for fall detection of a video file

Hello @Aruna, You can refer this for your ...READ MORE

Dec 2, 2020 in Python by Niroj
• 82,880 points
871 views
0 votes
1 answer

I installed windows 10 through vmware workstation . I want to connect remote machine using python winrm im getting error

Hey, @Natraj, This basically means that no response ...READ MORE

Dec 2, 2020 in Python by Gitika
• 65,910 points
764 views
0 votes
1 answer

AssertionError: <class 'numpy.ndarray'>

Same problem here bro! READ MORE

Dec 8, 2020 in Python by Bijoy
4,020 views
0 votes
1 answer

Are static class variables possible in Python?

Variables declared inside the class definition, but ...READ MORE

Nov 30, 2020 in Python by Gitika
• 65,910 points
371 views
0 votes
1 answer

What is the difference between an abstract function and a virtual function?

An abstract function cannot have functionality. You're basically ...READ MORE

Nov 30, 2020 in Python by Gitika
• 65,910 points
733 views
0 votes
1 answer

What is the difference between Python's list methods append and extend?

Appends object at the end. x = [1, ...READ MORE

Nov 30, 2020 in Python by Gitika
• 65,910 points
801 views
0 votes
1 answer

Difference between __str__ and __repr__?

The default implementation is useless (it’s hard ...READ MORE

Nov 30, 2020 in Python by Gitika
• 65,910 points
583 views
0 votes
1 answer

What is the difference between an interface and abstract class?

Interfaces An interface is a contract: The person writing ...READ MORE

Nov 30, 2020 in Python by Gitika
• 65,910 points
619 views
0 votes
1 answer

my Py Audio is not Downloading what should I do

Hello @S.P.D, First try to check your python ...READ MORE

Nov 30, 2020 in Python by Niroj
• 82,880 points
540 views
0 votes
1 answer

can someone please help me with python?

Hello @ Anee, Code: num1 = int(input("Enter First Number: ")) num2 ...READ MORE

Nov 30, 2020 in Python by Niroj
• 82,880 points
480 views
0 votes
1 answer

Error "Failed to load tensorflow runtime"

Hello, Try to downgrade protobuf, this worked for ...READ MORE

Nov 30, 2020 in Python by Niroj
• 82,880 points
380 views
0 votes
1 answer

fatal error: Python.h: No such file or directory

On Ubuntu, I was running Python 3 ...READ MORE

Nov 28, 2020 in Python by Gitika
• 65,910 points
3,919 views
0 votes
1 answer

What is the Python 3 equivalent of “python -m SimpleHTTPServer”

The SimpleHTTPServer module has been merged into http.server in Python 3.0. ...READ MORE

Nov 28, 2020 in Python by Gitika
• 65,910 points
478 views
0 votes
1 answer

Extracting extension from filename in Python

Yes. Use os.path.splitext >>> import os >>> filename, file_extension = ...READ MORE

Nov 27, 2020 in Python by Gitika
• 65,910 points
510 views
0 votes
1 answer

Difference between python programing and scripting

Hi,@Sashi, Generally, all the scripting languages are considered ...READ MORE

Nov 27, 2020 in Python by Gitika
• 65,910 points
16,727 views
0 votes
1 answer

How do I find the a referring sites URL in node?

Hii, In express 4.x: req.get('Referrer') This will also check both spellings of ...READ MORE

Nov 27, 2020 in Python by Niroj
• 82,880 points
2,324 views
0 votes
1 answer

Python code for motion detection

Hey, @Sushruth, Here the code goes for Motion Detector.py import ...READ MORE

Nov 27, 2020 in Python by Gitika
• 65,910 points
1,308 views
0 votes
1 answer

How do I get a substring of a string in Python?

>>> x = "Hello World!" >>> x[2:] 'llo World!' >>> ...READ MORE

Nov 27, 2020 in Python by Gitika
• 65,910 points
353 views
0 votes
1 answer

How do you use a variable in a regular expression?

Instead of using the /regex/g syntax, you can construct ...READ MORE

Nov 26, 2020 in Python by Gitika
• 65,910 points
331 views
0 votes
1 answer

How to print without newline or space?

In Python 3, you can use the sep= and end= parameters ...READ MORE

Nov 26, 2020 in Python by Gitika
• 65,910 points
484 views
0 votes
1 answer

How to check if a string contains a substring in Bash?

string='My long string' if [[ $string == ...READ MORE

Nov 26, 2020 in Python by Gitika
• 65,910 points
1,206 views
0 votes
1 answer

How to import other Python files?

Just import file without the '.py' extension. You can mark ...READ MORE

Nov 26, 2020 in Python by Gitika
• 65,910 points
986 views
0 votes
1 answer

Check if a given key already exists in a dictionary?

in is the intended way to test for ...READ MORE

Nov 26, 2020 in Python by Gitika
• 65,910 points
689 views
0 votes
1 answer

How can I get a list of locally installed Python modules?

Do not use with pip > 10.0! My ...READ MORE

Nov 26, 2020 in Python by anonymous
• 65,910 points
347 views