Most voted questions in Python

0 votes
1 answer

How can I Get Laplacian pyramid using opencv

As far as I can see you ...READ MORE

Sep 4, 2018 in Python by Priyaj
• 58,090 points
1,740 views
0 votes
2 answers

NameError: name 'raw_input' is not defined

Hi, There may a problem with your python ...READ MORE

Jun 25, 2020 in Python by MD
• 95,440 points
31,922 views
0 votes
1 answer

Python `if x is not None` or `if not x is None`?

There's no performance difference, as they compile ...READ MORE

Sep 3, 2018 in Python by Priyaj
• 58,090 points
2,424 views
0 votes
1 answer

Python: nested 'for' loops

Could use itertools: >>> for comb in itertools.combinations_with_replacement(range(9, -1, ...READ MORE

Sep 3, 2018 in Python by Priyaj
• 58,090 points
828 views
0 votes
1 answer

The equivalent of a GOTO in python ​​

Gotos are universally reviled in computer science ...READ MORE

Sep 3, 2018 in Python by Priyaj
• 58,090 points
12,330 views
0 votes
1 answer

How to create new folder?

You can create a folder with os.makedirs() and use os.path.exists() to ...READ MORE

Sep 3, 2018 in Python by Priyaj
• 58,090 points
565 views
0 votes
1 answer

Is there a foreach function in python and is there a way to implement it if there isnt any

Every occurence of "foreach" I've seen (PHP, ...READ MORE

Aug 31, 2018 in Python by charlie_brown
• 7,720 points
792 views
0 votes
1 answer

How to implement Hashmaps in Python

Python dictionary is a built-in type that supports ...READ MORE

Aug 31, 2018 in Python by charlie_brown
• 7,720 points
800 views
0 votes
1 answer

How to Print a List in Python

ou are using Python 2.x syntax with ...READ MORE

Aug 31, 2018 in Python by charlie_brown
• 7,720 points
795 views
0 votes
1 answer

When I create and remove files rapidly on windows using python I get WindowsError (Error 5)

Here's the short answer: disable any antivirus or ...READ MORE

Aug 31, 2018 in Python by charlie_brown
• 7,720 points
1,698 views
0 votes
1 answer

Django form validation: making “required” conditional?

This is done with the clean method on the ...READ MORE

Aug 30, 2018 in Python by Priyaj
• 58,090 points
6,004 views
0 votes
2 answers

In List of Dicts, find min() value of a common Dict field

lst = [{'price': 99, 'barcode': '2342355'}, {'price': ...READ MORE

Aug 31, 2018 in Python by Omkar
• 69,230 points
7,298 views
0 votes
1 answer

How to replace values with None in Pandas data frame in Python?

Actually in later versions of pandas this ...READ MORE

Aug 30, 2018 in Python by Priyaj
• 58,090 points
11,219 views
0 votes
1 answer

Python class inherits object

Python 3.x: class MyClass(object): = new-style class class MyClass: = new-style ...READ MORE

Aug 30, 2018 in Python by Priyaj
• 58,090 points
606 views
0 votes
1 answer

Linux command-line call not returning what it should from os.system?

What gets returned is the return value ...READ MORE

Aug 29, 2018 in Python by Priyaj
• 58,090 points
669 views
0 votes
1 answer

Python vs Cpython

So what is CPython? CPython is the original ...READ MORE

Aug 29, 2018 in Python by Priyaj
• 58,090 points
11,542 views
0 votes
1 answer

Examples for string find in Python

you can use str.index too: >>> 'sdfasdf'.index('cc') Traceback ...READ MORE

Aug 29, 2018 in Python by Priyaj
• 58,090 points
600 views
0 votes
3 answers

What is the python keyword “with” used for?

The with statement in Python simplifies exception ...READ MORE

Jul 19, 2019 in Python by rahul
• 360 points
1,242 views
0 votes
2 answers

How to create new folder?

import os try: os.makedirs(path) except ...READ MORE

Aug 31, 2018 in Python by Omkar
• 69,230 points
633 views
0 votes
1 answer

Python ctypes segmentation fault when rootfs is read-only and /tmp is noexec

I cant really seem to reproduce the ...READ MORE

Aug 28, 2018 in Python by anonymous
817 views
0 votes
1 answer

How do I know what's going to be deleted?

An easy system would be to add ...READ MORE

Aug 28, 2018 in Python by anonymous
562 views
0 votes
1 answer

Python using basicConfig method to log to console and file

Try this working fine(tested in python 2.7) ...READ MORE

Aug 27, 2018 in Python by Priyaj
• 58,090 points
9,662 views
0 votes
1 answer

Python variable declaration

Okay, first things first. There is no such ...READ MORE

Aug 27, 2018 in Python by Priyaj
• 58,090 points
370 views
0 votes
1 answer

What is the meaning of “int(a[::-1])” in Python?

Assumming a is a string. The Slice ...READ MORE

Aug 27, 2018 in Python by Priyaj
• 58,090 points
6,164 views
0 votes
1 answer

Python: Lambda function in List Comprehensions

The first one create a single lambda ...READ MORE

Aug 27, 2018 in Python by Priyaj
• 58,090 points
2,428 views
0 votes
3 answers

Python exit commands - why so many and when should each be used?

The functions* quit(), exit(), and sys.exit() function in the same way: ...READ MORE

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

What does eval() in Python do?

The eval function lets a Python program ...READ MORE

Aug 24, 2018 in Python by Priyaj
• 58,090 points
549 views
0 votes
1 answer

What's the canonical way to check for type in Python?

To check if o is an instance ...READ MORE

Aug 24, 2018 in Python by Priyaj
• 58,090 points
706 views
0 votes
1 answer

Create a constant in Python?

No there is not. You cannot declare ...READ MORE

Aug 24, 2018 in Python by Priyaj
• 58,090 points
28,571 views
0 votes
1 answer

How random.seed(): is used in python?

Pseudo-random number generators work by performing some ...READ MORE

Aug 24, 2018 in Python by Priyaj
• 58,090 points
441 views
0 votes
3 answers

'python' is not recognized as an internal or external command

Try "py" instead of "python" from command line: C:\Users\Cpsa>py Python 3.4.1 (v3.4.1:c0e311e010fc, May ...READ MORE

Feb 8, 2022 in Python by Rahul
• 9,670 points
2,142 views
0 votes
1 answer

How can I expose callbacks to Fortran using Python

The code that I've written below. The ...READ MORE

Aug 24, 2018 in Python by aryya
• 7,450 points
1,352 views
0 votes
1 answer

Is there anyway to obtain the full abstract from a 'PUBmed' article using bioPython

Hey Charlie, it's certainly possible to pull ...READ MORE

Aug 24, 2018 in Python by aryya
• 7,450 points
3,069 views
0 votes
1 answer

Replace First and Last Word of String in the Most Pythonic Way

import re a = " this is a ...READ MORE

Aug 23, 2018 in Python by aryya
• 7,450 points
2,593 views
0 votes
1 answer

Flask App Using WTForms with SelectMultipleField

Flask returns request.form as a werkzeug MultiDict ...READ MORE

Aug 23, 2018 in Python by aryya
• 7,450 points
19,090 views
0 votes
1 answer

How to install Python MySQLdb module using pip?

It's easy to do, but hard to ...READ MORE

Aug 20, 2018 in Python by charlie_brown
• 7,720 points
1,753 views
0 votes
1 answer

Pointers in Python?

I want form.data['field'] and form.field.value to always have the same value This ...READ MORE

Aug 20, 2018 in Python by charlie_brown
• 7,720 points
901 views
0 votes
1 answer

Creating an empty list in Python

Here is how you can test which ...READ MORE

Aug 17, 2018 in Python by Priyaj
• 58,090 points
906 views
0 votes
1 answer

Python string formatting: % vs. .format

To answer your first question... .format just ...READ MORE

Aug 17, 2018 in Python by Priyaj
• 58,090 points
752 views
0 votes
1 answer

How do you create nested dict in Python?

It is important to remember when using ...READ MORE

Aug 16, 2018 in Python by Priyaj
• 58,090 points
3,261 views
0 votes
1 answer

How can I check for NaN in Python?

math.isnan() Checks if the float x is a ...READ MORE

Aug 16, 2018 in Python by Priyaj
• 58,090 points
23,828 views
0 votes
1 answer

Python using basicConfig method to log to console and file

I can't reproduce it on Python 3.3. ...READ MORE

Aug 14, 2018 in Python by aryya
• 7,450 points
893 views
0 votes
1 answer

How do you express binary literals in Python?

For reference—future Python possibilities: Starting with Python 2.6 you ...READ MORE

Aug 14, 2018 in Python by aryya
• 7,450 points
742 views
0 votes
1 answer

Add new keys to a dictionary?

>>> d = {'key':'value'} >>> print(d) {'key': ...READ MORE

Aug 13, 2018 in Python by Priyaj
• 58,090 points
384 views
0 votes
1 answer

'Syntax Error: invalid syntax' for no apparent reason

You're missing a close paren in this ...READ MORE

Aug 13, 2018 in Python by Priyaj
• 58,090 points
2,244 views
0 votes
1 answer

How do you get the logical xor of two variables in Python?

What i found is that you can use ...READ MORE

Aug 10, 2018 in Python by Priyaj
• 58,090 points
11,361 views
0 votes
1 answer

What is the difference between re.search and re.match?

The theoritical approach can be this way, re.match is ...READ MORE

Aug 10, 2018 in Python by Priyaj
• 58,090 points
11,472 views
0 votes
2 answers

Replacements for switch statement in Python?

The recommended path for Python 3.10 which ...READ MORE

Feb 9, 2022 in Python by Soham
• 9,700 points
605 views
0 votes
1 answer

A basic question about “while true”

while True means loop forever. The while ...READ MORE

Aug 8, 2018 in Python by bug_seeker
• 15,520 points
496 views
0 votes
1 answer

How to read/process command line arguments?

The canonical solution in the standard library ...READ MORE

Aug 8, 2018 in Python by bug_seeker
• 15,520 points
373 views