In Python, how do I obtain the current frame?

import sys sys._getframe(number) The number being 0 for the current frame and 1 for the frame up and so on up. The best introduction I have found to frames in python is here However, look at the inspect module as it does most common things you want to do with frames.

Django formsets: make first required?

Found a better solution: class RequiredFormSet(BaseFormSet): def __init__(self, *args, **kwargs): super(RequiredFormSet, self).__init__(*args, **kwargs) for form in self.forms: form.empty_permitted = False Then create your formset like this: MyFormSet = formset_factory(MyForm, formset=RequiredFormSet) I really don’t know why this wasn’t an option to begin with… but, whatever. It only took a few hours of my life to figure … Read more

How to resolve the error, “module umap has no attribute UMAP”.. I tried installing & reinstalling umap but didn’t work to me

To use UMAP you need to install umap-learn not umap. So, in case you installed umap run the following commands to uninstall umap and install upam-learn instead: pip uninstall umap pip install umap-learn And then in your python code make sure you are importing the module using: import umap.umap_ as umap Instead of import umap

Why is subtraction faster than addition in Python?

I can reproduce this on my Q6600 (Python 2.6.2); increasing the range to 100000000: (‘+=’, 11.370000000000001) (‘-=’, 10.769999999999998) First, some observations: This is 5% for a trivial operation. That’s significant. The speed of the native addition and subtraction opcodes is irrelevant. It’s in the noise floor, completely dwarfed by the bytecode evaluation. That’s talking about … Read more