Most answered questions in Python

0 votes
1 answer

Numpy: Multiplying large arrays with dtype=int8 is SLOW

Unfortunately, as correctly underlined in the comments, the ...READ MORE

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

Plot a k-distance graph in python

You probably want to use the matrix ...READ MORE

Sep 5, 2018 in Python by Priyaj
• 58,090 points
4,710 views
0 votes
1 answer

Python error: No handlers could be found for logger “xhtml2pdf”

The only solution is to define a ...READ MORE

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

How to create transaction in GnuCash in response to an email?

Here's a template, along with a couple ...READ MORE

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

How does time series analysis with statsmodels work?

I'd really like to see a data ...READ MORE

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

Manage websockets across multiple servers / workers

So I am only familiar with Socket.IO ...READ MORE

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

How to resize image canvas to maintain square aspect ratio in Python, OpenCv

Building on Alexander-Reynolds answer above, here is ...READ MORE

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

Can I configure Django runserver to reload when static or non-python files are changed?

There is no need to reload server, ...READ MORE

Sep 4, 2018 in Python by Priyaj
• 58,090 points
6,730 views
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,754 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,444 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
837 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,343 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
588 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
799 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
809 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
805 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,709 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,006 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,247 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
614 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
672 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,549 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
607 views
+1 vote
1 answer

Understanding Python super() with __init__() methods

It's been noted that in Python 3.0+ ...READ MORE

Aug 28, 2018 in Python by Priyaj
• 58,090 points
3,893 views
+1 vote
1 answer

What's the difference between eval, exec, and compile in Python?

exec is not an expression: a statement ...READ MORE

Aug 28, 2018 in Python by Priyaj
• 58,090 points
4,715 views
+1 vote
1 answer

Accessing the index in 'for' loops?

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

Aug 28, 2018 in Python by Priyaj
• 58,090 points
398 views
+1 vote
1 answer

How do you express binary literals in Python?

Starting with Python 2.6 you can express ...READ MORE

Aug 28, 2018 in Python by Priyaj
• 58,090 points

edited Dec 21, 2023 by Khan Sarfaraz 3,824 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
825 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
577 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,692 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
380 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,172 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,437 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
557 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
715 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,582 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
454 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,361 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,076 views
+1 vote
1 answer

Why does x,y = zip(*zip(a,b)) work in Python?

I'm extremely new to Python so this ...READ MORE

Aug 23, 2018 in Python by Priyaj
• 58,090 points
1,385 views
+2 votes
1 answer

How do you make a block comment in python?

''' This is a multiline comment. I ...READ MORE

Aug 23, 2018 in Python by Priyaj
• 58,090 points
776 views
+1 vote
1 answer

How to print an error in Python?

For Python 2.6 and later and Python ...READ MORE

Aug 23, 2018 in Python by Priyaj
• 58,090 points
1,192 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,601 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,110 views
+1 vote
1 answer

Zip lists in Python

zip takes a bunch of lists likes a: ...READ MORE

Aug 22, 2018 in Python by Priyaj
• 58,090 points
553 views
+1 vote
1 answer

What is the difference between range and xrange functions in Python 2.X?

xrange only stores the range params and ...READ MORE

Aug 22, 2018 in Python by Priyaj
• 58,090 points
2,124 views
+1 vote
1 answer

Understanding Pickling in Python

While others have pointed to the Python ...READ MORE

Aug 22, 2018 in Python by Priyaj
• 58,090 points
632 views
+1 vote
1 answer

How to write the Fibonacci Sequence?

Efficient Pythonic generator of the Fibonacci sequence I ...READ MORE

Aug 21, 2018 in Python by Priyaj
• 58,090 points
1,032 views
+1 vote
1 answer

Reading a large file, line by line in Python

The correct, fully Pythonic way to read ...READ MORE

Aug 21, 2018 in Python by Priyaj
• 58,090 points
731 views
+1 vote
1 answer

What is the function for Factorial in Python

Easiest way: math.factorial(x) (available in 2.6 and ...READ MORE

Aug 21, 2018 in Python by Priyaj
• 58,090 points

edited Aug 21, 2018 by Omkar 1,141 views