Latest questions in Python

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,706 views
+1 vote
2 answers

Does 'finally' always execute in Python?

The "finally" executes almost everytime. But there ...READ MORE

Aug 31, 2018 in Python by Omkar
• 69,230 points
5,509 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,005 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,313 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,241 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
612 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
671 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,546 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
603 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,264 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
640 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,886 views
+1 vote
2 answers

Remove all whitespace in a string in Python

You can also use regular expressions for ...READ MORE

Aug 31, 2018 in Python by Omkar
• 69,230 points
16,895 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,710 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
392 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,819 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
824 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
571 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,689 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
374 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,168 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,434 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,126 views
+1 vote
3 answers

What are the ways of detecting outliners in Python

code from http://eurekastatistics.com/using-the-median-absolute-deviation-to-find-outliers  This uses the L1 distance ...READ MORE

Aug 24, 2018 in Python by eatcodesleeprepeat
• 4,710 points

reshown Aug 24, 2018 by Priyaj 1,027 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
554 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
709 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,577 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
446 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,149 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,356 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,074 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,382 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
770 views
+7 votes
8 answers

Difference for string comparison in Python: 'is' vs. ==

If we use "==" means both variables ...READ MORE

Sep 3, 2018 in Python by Parul Raheja
1,860 views
+1 vote
2 answers

How to use the pass statement in Python

In Python programming, pass is a null statement. The ...READ MORE

Apr 5, 2019 in Python by anonymous
792 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,188 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,598 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,104 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
550 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,120 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
630 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,030 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
727 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,135 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,770 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
912 views
+1 vote
2 answers

Python string formatting: % vs. .format

Using Python format() function is what the ...READ MORE

Apr 11, 2019 in Python by Dasa Ravi
1,061 views
+1 vote
1 answer

How do I trim whitespace?

Whitespace on both sides: s = " \t ...READ MORE

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

How to check if a string is null in python

Try this: if cookie and not cookie.isspace(): # the ...READ MORE

Aug 20, 2018 in Python by Priyaj
• 58,090 points
22,729 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
911 views