default

python function: how to unset a default argument value

python function: how to unset a default argument value Question: if i have def (a=10, b=2): … how do I unset a=1? I was told I need to not set ‘a’ but I can’t find how to do that on google, it just sets itself to the default value if I don’t have it, and …

Total answers: 2

Why mutable default parameter behaves this way?

Why mutable default parameter behaves this way? Question: I’m aware of mutable parameter behavior. Why the list is not set up to None when I send and unpack **dictionary as argument? The common_header.png repeads, it means is stored in list. That is weird to me and I couldn’t find answer for the question… I’m learning, …

Total answers: 2

How to add a property to a child dataclass before a default property?

How to add a property to a child dataclass before a default property? Question: Let’s suppose that I have a dataclass A. The dataclass A contains some property with a default value. Let’s suppose that I want to extend that dataclass with a dataclass B. I need to add some non-default property to the dataclass …

Total answers: 1

Workaround for Cython bindings library to C++ that lacks nullary constructor?

Workaround for Cython bindings library to C++ that lacks nullary constructor? Question: I’m working on a set of Cython bindings to expose a C++ compression library in python. The library uses the Pimpl pattern and, in particular, has no default empty constructors. I’m wrestling with using a class method that returns a CompressionConfig object, which …

Total answers: 2

permission denied on Mac

permission denied on Mac Question: I want to change the default version of my Python on Mac from Python2 to Python3. However, when I try to do that, it says that the permission is denied. Here is what I have tried: ls -l /usr/local/bin/python* The output was: lrwxr-xr-x 1 root wheel 69 Jun 21 10:41 …

Total answers: 2

make python3.5 as default in AWS?

make python3.5 as default in AWS? Question: Is there a way to make python3.5 as the default python in AWS. every time i try the next time i connect python2.7 is the default one and pip 6 is the last version, knowing that I did updated it some minutes before. here is the method i …

Total answers: 8

Change nltk.download() path directory from default ~/ntlk_data

Change nltk.download() path directory from default ~/ntlk_data Question: I was trying to download/update python nltk packages on a computing server and it returned this [Errno 122] Disk quota exceeded: error. Specifically: [nltk_data] Downloading package stop words to /home/sh2264/nltk_data… [nltk_data] Error downloading u’stopwords’ from [nltk_data] <https://raw.githubusercontent.com/nltk/nltk_data/gh- [nltk_data] pages/packages/corpora/stopwords.zip>: [Errno 122] [nltk_data] Disk quota exceeded: [nltk_data] u’/home/sh2264/nltk_data/corpora/stopwords.zip …

Total answers: 6

What is the default Django session lifetime and how to change it?

What is the default Django session lifetime and how to change it? Question: I can’t find a setting for the default session lifetime in https://docs.djangoproject.com/en/1.10/ref/settings/. I know this can be changed manually (How to expire Django session in 5minutes?). Asked By: Siegmeyer || Source Answers: The setting you are looking for is SESSION_COOKIE_AGE, the default …

Total answers: 2

argparse default option based on another option

argparse default option based on another option Question: Suppose I have an argparse python script: import argparse parser = argparse.ArgumentParser() parser.add_argument("–foo", required=True) Now I want to add another option –bar, which would default to appending "_BAR" to whatever was specified by –foo argument. My goal: >>> parser.parse_args([‘–foo’, ‘FOO’]) >>> Namespace(foo=’FOO’, bar="FOO_BAR") AND >>> parser.parse_args([‘–foo’, ‘FOO’, …

Total answers: 2

How can I return a default value for an attribute?

How can I return a default value for an attribute? Question: I have an object myobject, which might return None. If it returns None, it won’t return an attribute id: a = myobject.id So when myobject is None, the stament above results in a AttributeError: AttributeError: ‘NoneType’ object has no attribute ‘id’ If myobject is …

Total answers: 7