Why does list.append evaluate to false in a boolean context?

Why does list.append evaluate to false in a boolean context?

Is there a reason being list.append evaluating to false? Or is it just the C convention of returning 0 when successful that comes into play?>>> u = []>>> not u.append(6)True 1:Most Python methods that mutate a container in-place return N

When is .then(success, fail) considered an antipattern for promises?

When is .then(success, fail) considered an antipattern for promises?

I had a look at the bluebird promise FAQ, in which it mentions that .then(success, fail) is an antipattern. I don't quite understand its explanation as for the try and catch. What's wrong with this the following?some_promise_call().then(fun

How to install a python library manually

How to install a python library manually

I built quickfix engine (http://www.quickfixengine.org/) for one of my tasks and also built in python support for it.Unfortunately this is a multi user env and I dont have access to the python installation path. Thus the make install comman

How can I create a SQLite3 database file using a SQL command file?

How can I create a SQLite3 database file using a SQL command file?

I have a file which contains some SQL commands, something that looks like this:CREATE DATABASE IF NOT EXISTS `db_name`;USE `db_name`;CREATE TABLE IF NOT EXISTS `customers` ( `id` int(10) unsigned NOT NULL, `f_name` varchar(50) DEFAULT NUL

Python convert tuple to array [duplicate]

Python convert tuple to array [duplicate]

This question already has an answer here: Making a flat list out of list of lists in Python 33 answers How can I convert at 3-Dimensinal tuple into an

Jupyter: can't create new notebook?

Jupyter: can't create new notebook?

I have some existing Python code that I want to convert to a Jupyter notebook. I have run: jupyter notebookNow I can see this in my browser:But how do I create a new notebook? The Notebook link in the menu is greyed out, and I can't see any

Switch Python Version for Vim & Syntastic

Switch Python Version for Vim & Syntastic

Is it possible to change the python version used by syntastic for syntax checking?As the Issue https://github.com/scrooloose/syntastic/issues/385 indicates I could use virtual-env. But is it also possible just with syntastic or vim command

Using Python, how do you untar purely in memory?

Using Python, how do you untar purely in memory?

I'm working in an environment where I can't save anything to disk. I need to be able to pull tar files and unzip them without saving to disk. This seems to fail:I've tried this but it tosses errors:# fetch.pyfrom cStringIO import StringIOim

How to unzip an Array?

How to unzip an Array?

How to unzip an Array in Ruby like this examples in Python:>>> x = [1, 2, 3]>>> y = [4, 5, 6]>>> zipped = zip(x, y)>>> zipped[(1, 4), (2, 5), (3, 6)]>>> x2, y2 = zip(*zipped)>>> x == list(x2) and y == list(y2) 1:Use transpose:> zipped =

Change a string of integers separated by spaces to a list of int

Change a string of integers separated by spaces to a list of int

How do i make something likex = '1 2 3 45 87 65 6 8'>>> foo(x)[1,2,3,45,87,65,6,8]I'm completely stuck, if i do it by index, then the numbers with more than 1 digit will be broken down. Help please. 1:You can use a list comprehension in

What are the implications of running python with the optimize flag?

What are the implications of running python with the optimize flag?

I cannot seem to find a good simple explanation of what python does differently when running with the -O or optimize flag. 1:assert statements are completely eliminated, as are statement blocks of the form if __debug__: ... (so you can

Why won't re.groups() give me anything for my one correctly-matched group?

Why won't re.groups() give me anything for my one correctly-matched group?

When I run this code:print re.search(r'1', '1').groups() I get a result of (). However, .group(0) gives me the match.Shouldn't groups() give me something containing the match?Update: Thanks for the answers. So that means if I do re.search()

Reserve memory for list in Python?

Reserve memory for list in Python?

When programming in Python, is it possible to reserve memory for a list that will be populated with a known number of items, so that the list will not be reallocated several times while building it? I've looked through the docs for a Pytho

Lemmatizer in R or python (am, are, is -> be?) [closed]

Lemmatizer in R or python (am, are, is -> be?) [closed]

I'm not a [computational] linguistic, so please excuse my supper dummy-ness in this topic.According to Wikipedia, lemmatisation is defined as: Lemmatisation (or lemmatization) in linguistics, is the process of grouping together the differe

How do I programmatically send information to a web service in C# with .NET?

How do I programmatically send information to a web service in C# with .NET?

I know this sort of counts as reinventing the wheel here, but I need to know to communicate with a web service through http/soap/xml and web messages. The reason is I need to communicate with a third party web service for work, but there is

Pip install -e packages don't appear in Docker

Pip install -e packages don't appear in Docker

I have a requirements.txt file containing, amongst others:Flask-RQ==0.2-e git+https://token:[email protected]/user/repo.git#egg=repoWhen I try to build a Docker container using Docker Compose, it downloads both packages, and install

Django Pipeline, Heroku, and SASS

Django Pipeline, Heroku, and SASS

I've been trying to get django-pipeline setup so that I can compile and concat my assets. I would also like to remove the compiled css files from my repository to avoid merge conflicts in pull requests.I've been trying to get django-pipelin

can NLTK/pyNLTK work “per language” (i.e. non-english), and how?

can NLTK/pyNLTK work “per language” (i.e. non-english), and how?

How can I tell NLTK to treat the text in a particular language?Once in a while I write a specialized NLP routine to do POS tagging, tokenizing and etc. on a non-english (but still hindo-European) text domain.This question seem to address on

How do you call an instance of a class in Python?

How do you call an instance of a class in Python?

This is inspired by a question I just saw, "Change what is returned by calling class instance", but was quickly answered with __repr__ (and accepted, so the questioner did not actually intend to call the instance).Now calling an instance of

How to speed up python's 'turtle' function and stop it freezing at the end

How to speed up python's 'turtle' function and stop it freezing at the end

I have written a turtle program in python, but there are two problems.It goes way too slow for larger numbers, I was wonder how I can speed up turtle.It freezes after it finishes and when clicked on, says 'not responding'This is my code so

blank lines in file after sorting content of a text file in python

blank lines in file after sorting content of a text file in python

I have this small script that sorts the content of a text file# The built-in function `open` opens a file and returns a file object.# Read mode opens a file for reading only.try: f = open("tracks.txt", "r") try: # Read the enti

PIL: ImportError: The _imaging extension was built for another version of pillow or PIL

PIL: ImportError: The _imaging extension was built for another version of pillow or PIL

I get the error:---------------------------------------------------------------------------ImportError Traceback (most recent call last) in ()-- 1 from PIL import ImageC:\Anaconda\lib\site-packages\PIL\Image.py

OpenCV/Python: read specific frame using VideoCapture

OpenCV/Python: read specific frame using VideoCapture

Is there a way to get a specific frame using VideoCapture() method?My current code is:import numpy as npimport cv2cap = cv2.VideoCapture('video.avi')This is my reference tutorial. 1:Thank you GPPK. The video parameters should be given as

Removing \\u2018 and \\u2019 character

Removing \\u2018 and \\u2019 character

I am using Beautiful Soup to parse webpages and printing the name of the webpages visited on the terminal. However, often the name of the webpage has single right (\u2018) and left(\u2019) character which the python can't print as it gives

Convert a LaTex formula to a type that can be used inside SymPy

Convert a LaTex formula to a type that can be used inside SymPy

I want to parse LaTeX formulas and directly use them as SymPy expressions. In other words, what I need is something similar to sympify:from sympy import sympifyf = sympify('x^2 + sin(y) + 1/2')print fbut that can take LaTeX expressions (str