standard-library

Python negate boolean function

Python negate boolean function Question: A python boolean function can easily be negated with lambda functions, but it’s a bit verbose and hard to read for something so basic, for example: def is_even(n): return n % 2 == 0 odds_under_50 = filter(lambda x: not is_even(x), range(50)) I’m wondering if there is a function to do …

Total answers: 4

Why do some built-in Python functions only have pass?

Why do some built-in Python functions only have pass? Question: I wanted to see how a math.py function was implemented, but when I opened the file in PyCharm I found that all the functions are empty and there is a simple pass. For example: def ceil(x): # real signature unknown; restored from __doc__ “”” ceil(x) …

Total answers: 2

What is the opposite of python's ord() function?

What is the opposite of python's ord() function? Question: I found out about Python’s ord() function which returns corresponding Unicode codepoint value. But what is the opposite function, i.e. get char value by int? Edit: I’m new to SO, and couldn’t find the answer here, so decided to post in order to everyone could find …

Total answers: 2

Why does str.split not take keyword arguments?

Why does str.split not take keyword arguments? Question: I came across this – in my view – strange behaviour: “a b c”.split(maxsplit=1) TypeError: split() takes no keyword arguments Why does str.split() not take keyword arguments, even though it would make sense? I found this behavior both in Python2 and Python3. Asked By: Peter Smit || …

Total answers: 2

What are the differences amongst Python's "__get*__" and "_del*__" methods?

What are the differences amongst Python's "__get*__" and "_del*__" methods? Question: I just started learning Python a few months ago, and I’m trying to understand the differences between the different __get*__ methods: __get__ __getattr__ __getattribute__ __getitem___ And their __del*__ equivalents: __del__ __delattr__ __delete__ __delitem__ What are the differences between these? When should I use one …

Total answers: 1

Getting a machine's external IP address with Python

Getting a machine's external IP address with Python Question: Looking for a better way to get a machines current external IP #… Below works, but would rather not rely on an outside site to gather the information … I am restricted to using standard Python 2.5.1 libraries bundled with Mac OS X 10.5.x import os …

Total answers: 31

Is there a module for balanced binary tree in Python's standard library?

Is there a module for balanced binary tree in Python's standard library? Question: Is there a module for an AVL tree or a red–black tree or some other type of a balanced binary tree in the standard library of Python? Asked By: aeter || Source Answers: there is nothing of this sort in stdlib, as …

Total answers: 7

Most useful Python modules from the standard library?

Most useful Python modules from the standard library? Question: I am teaching a graduate level Python class at the University of Paris, and the students need to be introduced to the standard library. I want to discuss with them about some of the most important standard modules. What modules do you think are absolute musts? …

Total answers: 16