context in nested serializers django rest framework

Ok i found a working solution. I replaced the ChildSerializer assignment in the Parent class with a SerializerMethodField which adds the context. This is then passed to the get_fields method in my CustomModelSerializer: class ChildSerializer(CustomModelSerializer): class Meta: fields = (‘c_name’, ) model = Child class ParentSerializer(CustomModelSerializer): child = serializers.SerializerMethodField(‘get_child_serializer’) class Meta: model = Parent fields … Read more

Namespace vs regular package

Namespace packages As of Python 3.3, we get namespace packages. These are a special kind of package that allows you to unify two packages with the same name at different points on your Python-path. For example, consider path1 and path2 as separate entries on your Python-path: path1 +–namespace +–module1.py +–module2.py path2 +–namespace +–module3.py +–module4.py with … Read more

Execute Python script within Jupyter notebook using a specific virtualenv

Here’s what worked for me (non conda python): (MacOS, brew version of python. if you are working with system python, you may (will) need prepend each command with sudo) First activate virtualenv. If starting afresh then, e.g., you could use virtualenvwrapper: $ pip install virtualenvwrapper $ mkvirtualenv -p python2 py2env $ workon py2env # This … Read more

Debugging Numpy VisibleDeprecationWarning (ndarray from ragged nested sequences)

With a function that creates a ragged array: In [60]: def foo(): …: print(‘one’) …: x = np.array([[1],[1,2]]) …: return x …: In [61]: foo() one /usr/local/bin/ipython3:3: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, … Read more

Subprocess check_output returned non-zero exit status 1

The command yum that you launch was executed properly. It returns a non zero status which means that an error occured during the processing of the command. You probably want to add some argument to your yum command to fix that. Your code could show this error this way: import subprocess try: subprocess.check_output(“dir /f”,shell=True,stderr=subprocess.STDOUT) except … Read more