python
Double precision floating values in Python?
Decimal datatype Unlike hardware based binary floating point, the decimal module has a user alterable precision (defaulting to 28 places) which can be as large as needed for a given problem. If you are pressed by performance issuses, have a look at GMPY
Python Progress Bar
There are specific libraries (like this one here) but maybe something very simple would do: Note: progressbar2 is a fork of progressbar which hasn’t been maintained in years.
How to fix ‘Object arrays cannot be loaded when allow_pickle=False’ for imdb.load_data() function?
Here’s a trick to force imdb.load_data to allow pickle by, in your notebook, replacing this line: by this:
What do these operators mean (** , ^ , %, //)? [closed]
**: exponentiation ^: exclusive-or (bitwise) %: modulus //: divide with integral result (discard remainder)
Python foreach equivalent
Sure. A for loop.
How do I append one string to another in Python?
If you only have one reference to a string and you concatenate another string to the end, CPython now special cases this and tries to extend the string in place. The end result is that the operation is amortized O(n). e.g. used to be O(n^2), but now it is O(n). From the source (bytesobject.c): It’s … Read more
What is __init__.py for?
It used to be a required part of a package (old, pre-3.3 “regular package”, not newer 3.3+ “namespace package”). Here’s the documentation. Python defines two types of packages, regular packages and namespace packages. Regular packages are traditional packages as they existed in Python 3.2 and earlier. A regular package is typically implemented as a directory … Read more
Unzipping files in Python
That’s pretty much it!
Should I put #! (shebang) in Python scripts, and what form should it take?
The shebang line in any script determines the script’s ability to be executed like a standalone executable without typing python beforehand in the terminal or when double clicking it in a file manager (when configured properly). It isn’t necessary but generally put there so when someone sees the file opened in an editor, they immediately … Read more