Trending questions in Python

0 votes
1 answer

Explain split() and join() functions in Python?

Hey, @Roshni, You can use split() function to split a ...READ MORE

Jun 23, 2020 in Python by Gitika
• 65,910 points
8,099 views
0 votes
1 answer

Error: wn = trtl.Screen() AttributeError: 'Turtle' object has no attribute 'Screen

Hi, @There, It requires a very simple hack ...READ MORE

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

How do I check whether a file exists without exceptions?

 It's safer to use a try around the attempt ...READ MORE

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

ImportError: cannot import name 'API_KEY' from 'forwarder'

The AWS package in PyPI is not AWS's official ...READ MORE

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

How can I add new keys to a dictionary?

d = {'key': 'value'} print(d) # {'key': 'value'} d['mynewkey'] = ...READ MORE

Dec 17, 2020 in Python by Gitika
• 65,910 points
442 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,306 views
0 votes
1 answer

ValueError: arrays must all be same length

Hello, For your query you can refer this:https://www.programmersought.com/article/5321489391/ Hope ...READ MORE

Sep 21, 2020 in Python by Niroj
• 82,880 points
4,185 views
0 votes
0 answers

how to solve this

from nsepy import get_history from datetime import date import ...READ MORE

Dec 12, 2020 in Python by Pawan
• 120 points
685 views
0 votes
1 answer

Error:'QuerySet' object has no attribute 'remove'

Hello @kartik, You could do this: import itertools ids = ...READ MORE

Aug 12, 2020 in Python by Niroj
• 82,880 points
5,883 views
0 votes
1 answer

How to find local IP addresses using Python's stdlib?

Hello @kartik, Try this out: import socket s = socket.socket(socket.AF_INET, ...READ MORE

Dec 8, 2020 in Python by Niroj
• 82,880 points
766 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 17, 2020 in Python by Nikita
372 views
0 votes
1 answer

Error:Expected view to be called with a URL keyword argument named “pk”

Hello @kartik, View functions are called with the ...READ MORE

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

Accessing the index in 'for' loops?

Using an additional state variable, such as ...READ MORE

Dec 16, 2020 in Python by Gitika
• 65,910 points
393 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
953 views
0 votes
2 answers

How can I safely create a nested directory?

No need to put filename.txt For directory check path ...READ MORE

Nov 25, 2020 in Python by Deepak Chaurasia
1,368 views
0 votes
1 answer

“Least Astonishment” and the Mutable Default Argument

Actually, this is not a design flaw, ...READ MORE

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

What does the “yield” keyword do?

To understand what yield does, you must understand what generators are. ...READ MORE

Dec 16, 2020 in Python by Gitika
• 65,910 points
350 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,203 views
0 votes
1 answer

ModuleNotFoundError: No module named 'pymongo'

Hi@akhtar, It seems you don't have a Pymongo module ...READ MORE

Jun 26, 2020 in Python by MD
• 95,440 points
7,797 views
0 votes
1 answer

Import a module from a relative path?

Assuming that both your directories are real ...READ MORE

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

Can anyone help me with this error: TypeError: list indices must be integers or slices, not str

Hi, @Varshap  It’s a TypeError, which tells us ...READ MORE

Nov 5, 2020 in Python by anonymous
• 65,910 points
2,048 views
0 votes
1 answer

Speed up millions of regex replacements in Python 3

One thing you can try is to ...READ MORE

Nov 19, 2020 in Python by Gitika
• 65,910 points
1,510 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
721 views
0 votes
1 answer

How to get the home directory in Python?

Hello, You need to use os.path.expanduser. This will ensure it works ...READ MORE

Nov 19, 2020 in Python by Niroj
• 82,880 points
1,471 views
+1 vote
2 answers

Python error "Python: can't assign to literal"

The way you're assigning variables is not ...READ MORE

Jun 17, 2019 in Python by Priya
15,086 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
869 views
0 votes
1 answer

How do I change the working directory in Python?

Hello @kartik, use os.chdir like this: os.chdir("/path/to/change/to") By the way, if you ...READ MORE

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

How do I check if a string contains a specific word?

You can use the strpos() function which is used ...READ MORE

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

I have created python chatbot using flask framework using yml file now i want to use json file what should i do now ?

Hello @golu , Try something like this: with open(yaml_file, 'r') ...READ MORE

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

How to iterate a Json file which has multiple key value pairs and also nested list as part of the file?

I think you need to create some ...READ MORE

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

How to get an absolute file path in Python?

Hello @kartik, Try this out: >>> import os >>> os.path.abspath("mydir/myfile.txt") 'C:/example/cwd/mydir/myfile.txt' Also ...READ MORE

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

Please Help me About this Pygame Error installing on pip

Hi, @Micheal, Download pygame‑1.9.3‑cp37‑cp37m‑win_amd64. While if you have a 64-bit ...READ MORE

Oct 12, 2020 in Python by Gitika
• 65,910 points
3,088 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
757 views
0 votes
1 answer

How can I open multiple files using “with open” in Python?

Hello @kartik, Just replace and with , and you're done: try: ...READ MORE

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

How can I open multiple files using “with open” in Python?

Hello, Just replace and with , and you're done: try: ...READ MORE

Nov 20, 2020 in Python by Niroj
• 82,880 points
1,304 views
+1 vote
2 answers

Error:Django gives Bad Request (400) when DEBUG = False

Tried this and it resolved all my ...READ MORE

Sep 25, 2020 in Python by Agaba
5,673 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
763 views
0 votes
1 answer

pandas._libs.tslib.OutOfBoundsDatetime: Out of bounds nanosecond timestamp

Hi@akhtar, I think you need to upgrade or reinstall ...READ MORE

Jul 16, 2020 in Python by MD
• 95,440 points
6,747 views
0 votes
1 answer

python pycharm is not proper working

Hi, @Webinar, Are you getting any kind of ...READ MORE

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

How to get all links and all elements that are clickable on a page of system dynamically?

Hello, You can do it by using find_elements_by_xpath() driver ...READ MORE

Aug 27, 2020 in Python by Niroj
• 82,880 points
4,924 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
982 views
0 votes
1 answer

How to choose the value and label from Django ModelChoiceField queryset?

Hello @kartik, In your Person model add: def __unicode__(self): ...READ MORE

Jul 29, 2020 in Python by Niroj
• 82,880 points
6,168 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
798 views
0 votes
1 answer

when I run this, I get TypeError: int() takes at most 2 arguments (3 given). How to solve this?

Hi@MUHAMMAD, You are trying to pass State in ...READ MORE

Sep 7, 2020 in Python by akhtar
• 38,230 points
4,464 views
0 votes
1 answer

ModuleNotFoundError: No module named 'line_profiler'.

Hi@akhtar, You need to install the module in ...READ MORE

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

How to get the SQL from a Django QuerySet?

Hello @kartik, Try this in your queryset: print my_queryset.query For ...READ MORE

Jun 23, 2020 in Python by Niroj
• 82,880 points
7,713 views
0 votes
1 answer

How to print an exception in Python?

Hello @kartik, For Python 2.6 and later and ...READ MORE

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

How to make a password validator without the use of the any()?

Hi, @There, Regarding your query I would suggest ...READ MORE

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

Installing PIL with pip

Install Xcode and Xcode Command Line Tools ...READ MORE

Sep 11, 2020 in Python by FogleBird
4,248 views