Trending questions in Python

+1 vote
1 answer

How to validate a field on update in DRF?

Hello @kartik, You can definitely do this using ...READ MORE

Jul 2, 2020 in Python by Niroj
• 82,880 points
9,131 views
0 votes
1 answer

Distance calculator

Hello @ Try this code: import math x, y = ...READ MORE

Nov 13, 2020 in Python by Niroj
• 82,880 points
3,340 views
0 votes
1 answer

How do I add a link from the Django admin page of one object to the admin page of a related object?

Hello @kartik, Set show_change_link to True (False by default) in your inline ...READ MORE

Jun 12, 2020 in Python by Niroj
• 82,880 points
9,964 views
0 votes
1 answer

how to solve the error : "ImportError: No module named Tkinter" in python.

Hi@Umama, If you are using Linux system, then ...READ MORE

Apr 27, 2020 in Python by MD
• 95,440 points
12,785 views
0 votes
1 answer

Is it possible to break a long line to multiple lines in Python?

Example of implicit line continuation: a = some_function( ...READ MORE

Jan 4, 2021 in Python by Gitika
• 65,910 points
1,014 views
0 votes
1 answer

Error:AttributeError: 'NoneType' object has no attribute 'extend'

Hello @kartik, You can use itertools.chain(): import itertools list2d = [[1,2,3], ...READ MORE

Nov 18, 2020 in Python by Niroj
• 82,880 points
3,027 views
0 votes
1 answer

Call a function from another file?

There isn't any need to add file.py while importing. ...READ MORE

Jan 5, 2021 in Python by Gitika
• 65,910 points
956 views
0 votes
1 answer

ValueError: must have exactly one of create/read/write/append mode

You can open a file for simultaneous ...READ MORE

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

Error: current transaction is aborted, commands ignored until end of transaction block?

Hii kartik, To get rid of the error, roll ...READ MORE

Apr 23, 2020 in Python by Niroj
• 82,880 points
12,045 views
0 votes
1 answer

How to match all occurrences of a regex?

Using scan should do the trick: string.scan(/regex/) READ MORE

Nov 25, 2020 in Python by Gitika
• 65,910 points
2,732 views
+1 vote
1 answer

ImportError: DLL load failed: The specified module could not be found.

Hi@akhtar, You may get this error if you ...READ MORE

Jun 22, 2020 in Python by MD
• 95,440 points
9,390 views
0 votes
1 answer

Error when running pip install: python setup.py egg_info"

ERROR: Command errored out with exit status ...READ MORE

Oct 29, 2020 in Python by anonymous
4,677 views
0 votes
1 answer

Import Error: No module named numpy?

Hello, I had numpy installed on the same ...READ MORE

Apr 14, 2020 in Python by Niroj
• 82,880 points
12,391 views
0 votes
1 answer

Python: ImportError: No module named Crypto.Cipher

Seems like the pycrypto package is not ...READ MORE

Jul 31, 2019 in Python by Hari
23,527 views
0 votes
1 answer

How to get the position of a character in Python?

There are two string methods for this, find() and index(). ...READ MORE

Jan 5, 2021 in Python by Gitika
• 65,910 points
800 views
0 votes
1 answer

How to drop all tables from the database with manage.py CLI in Django?

Hello @kartik, Python you can write your own ...READ MORE

Aug 7, 2020 in Python by Niroj
• 82,880 points
7,280 views
0 votes
3 answers

How to split a string into a list?

Using For loop This approach uses for loop ...READ MORE

Jan 4, 2021 in Python by David Samon
717 views
0 votes
1 answer

ImportError: Import by filename is not supported

Instead of doing a import like __import__ you can ...READ MORE

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

AttributeError: 'Group' object has no attribute 'user'

You can go through this: from django.contrib.auth.models import ...READ MORE

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

How to Remove specific characters from a string in Python?

Strings in Python are immutable (can't be changed). Because ...READ MORE

Jan 5, 2021 in Python by Gitika
• 65,910 points
688 views
0 votes
1 answer

How to update user password in Django Rest Framework?

Hello @kartik, Using a modelserializer might be an ...READ MORE

Jul 1, 2020 in Python by Niroj
• 82,880 points
8,777 views
0 votes
1 answer

How can I safely create a nested directory?

Python 3.5+: import pathlib pathlib.Path('/my/directory').mkdir(parents=True, exist_ok=True) pathlib.Path.mkdir as used above ...READ MORE

Nov 19, 2020 in Python by Gitika
• 65,910 points
2,719 views
0 votes
1 answer

How to store a dictionary on a Django Model?

Hello @kartik, If you don't need to query ...READ MORE

Jun 29, 2020 in Python by Niroj
• 82,880 points
8,842 views
0 votes
1 answer

How to find the occurrences of any word with more than two vowels in a file using regex?

for word in read: <--- iterating ...READ MORE

Nov 25, 2020 in Python by Gitika
• 65,910 points
2,430 views
0 votes
3 answers

How to add a new item to a dictionary in Python?

There is no add() , append() , or insert() method ...READ MORE

Jan 4, 2021 in Python by Reshma
585 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,313 views
0 votes
1 answer

Error: IndexError: list index out of range and python

IndexError The IndexError is raised when you attempt to retrieve ...READ MORE

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

Adding new column to existing DataFrame in Python pandas

Use the original df1 indexes to create ...READ MORE

Dec 23, 2020 in Python by Gitika
• 65,910 points
1,161 views
0 votes
3 answers

How can I sort a dictionary by key in python?

Another way could be: color_dict = {'red':'#FF0000',           'green':'#008000',           'black':'#000000',           'white':'#FFFFFF'} for ...READ MORE

Dec 28, 2020 in Python by Thomas Walenta
845 views
0 votes
1 answer

Error: Failed building wheel for MySql-Python

Hello @kartik, You need to install the following ...READ MORE

Jul 3, 2020 in Python by Niroj
• 82,880 points
8,652 views
0 votes
0 answers

can't compare offset-naive and offset-aware datetimes

While I'm Trying to Compare Two dates ...READ MORE

Dec 12, 2020 in Python by Mohamed
• 170 points
1,626 views
0 votes
1 answer

Error:Python NameError: name 'include' is not defined

Hello @kartik, On the basis of your information provided ...READ MORE

Jul 1, 2020 in Python by Niroj
• 82,880 points
8,692 views
0 votes
1 answer

ERROR: Could not build wheels for line-profiler which use PEP 517 and cannot be installed directly.

Hi@akhtar, If you are trying to install with pip ...READ MORE

Nov 5, 2020 in Python by MD
• 95,440 points
3,149 views
0 votes
1 answer

How to create a GUID/UUID in Python?

Hello @kartiK, If you need to pass UUID ...READ MORE

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

ModuleNotFoundError: No module named 'bs4'

Hi@akhtar, You need to install the bs4 package ...READ MORE

Jun 26, 2020 in Python by MD
• 95,440 points
8,817 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,889 views
0 votes
1 answer

ModuleNotFoundError: No module named 'cv2'

Check if it's installed properly, It will work ...READ MORE

Oct 12, 2020 in Python by Gitika
• 65,910 points
4,132 views
0 votes
1 answer

How to print colored text in Python?

This somewhat depends on what platform you ...READ MORE

Dec 17, 2020 in Python by Gitika
• 65,910 points
1,269 views
0 votes
0 answers

joining two images reading from one folder

Hi, i am trying to generating joined ...READ MORE

Jan 3, 2021 in Python by shapna
• 120 points
534 views
0 votes
1 answer

Remove final character from string

Simple: st = "abcdefghij" st = st[:-1] There is ...READ MORE

Jan 5, 2021 in Python by Gitika
• 65,910 points
410 views
0 votes
1 answer

ERROR: PyAudio-0.2.11-cp39-cp39-win_amd64.whl is not a supported wheel on this platform.

Hi, @Henll, You should download the version that ...READ MORE

Oct 22, 2020 in Python by Gitika
• 65,910 points
3,642 views
0 votes
1 answer

How to get value from form field in django framework?

Hello @kartik, Using a form in a view can ...READ MORE

Jun 30, 2020 in Python by Niroj
• 82,880 points
8,535 views
0 votes
1 answer

How to terminate a python script?

This can be done by importing the ...READ MORE

Aug 9, 2019 in Python by Arvind
• 3,040 points
22,618 views
0 votes
0 answers

AttributeError: 'Index' object has no attribute 'get_values'

parameters = pd.read_csv(params_filename, sep="\t") free_parameters = parameters.columns.get_values().to_list() free_parameters = ...READ MORE

Sep 7, 2020 in Python by Swastik
• 120 points
5,594 views
0 votes
1 answer

Error: Unhandled exception in thread started by Error in sys.excepthook:

I think the general idea of the ...READ MORE

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

What is the difference between driver.close() and driver.quit()?

They do a similar thing but not ...READ MORE

Apr 6, 2019 in Python by Yash
27,981 views
+1 vote
3 answers

While using pyttsx 3 , I am having the following ERROR, i have installed pypiwin32

Try this: pip uninstall pyttsx3 Then: pip install pyttsx3==2.71 READ MORE

Aug 12, 2020 in Python by Eghosa
7,141 views
0 votes
1 answer

How to import a module given the full path?

For Python 3.5+ use: import importlib.util spec = importlib.util.spec_from_file_location("module.name", ...READ MORE

Nov 25, 2020 in Python by Gitika
• 65,910 points
2,074 views
0 votes
1 answer

How can I return HTTP status code 204 from a Django view?

Hello, Try this: return HttpResponse(status=204) Hope it works!! ...READ MORE

Aug 17, 2020 in Python by Niroj
• 82,880 points
6,362 views
0 votes
3 answers

Is there a simple way to delete a list element by value?

There are three ways in which you ...READ MORE

Dec 28, 2020 in Python by Thomas Walenta
513 views