Python: argparse optional arguments without dashes

There is no way to get argparse to do this for you. However, you can make argparse accept any number of positional arguments: parser.add_argument(‘FILES’,nargs=”*”) options=parser.parse_args() file1,optional_files=options.FILES[0],options.FILES[1:] Of course, you may want to add some checks to make sure that at least 1 file was given, etc. EDIT I’m still not 100% sure what you want … Read more

Getting correct string length in Python for strings with ANSI color codes

The pyparsing wiki includes this helpful expression for matching on ANSI escape sequences: ESC = Literal(‘\x1b’) integer = Word(nums) escapeSeq = Combine(ESC + ‘[‘ + Optional(delimitedList(integer,’;’)) + oneOf(list(alphas))) Here’s how to make this into an escape-sequence-stripper: from pyparsing import * ESC = Literal(‘\x1b’) integer = Word(nums) escapeSeq = Combine(ESC + ‘[‘ + Optional(delimitedList(integer,’;’)) + oneOf(list(alphas))) … Read more

How to filter choices in Django2’s autocomplete_fields?

If you are using autocomplete_fields for a ManyToManyField on ‘self’, this example will exclude the current object. Get the current object’s id by overriding get_form: field_for_autocomplete = None def get_form(self, request, obj=None, **kwargs): if obj: self.field_for_autocomplete = obj.pk return super(MyAdmin, self).get_form(request, obj, **kwargs) Next, override get_search_results. Modify the queryset only for your model’s autocomplete URI: … Read more

export conda environment without prefix variable which shows local path to executable

This question was already addressed here, but without a real explanation on the role of prefix. At least there is a solution to exclude the prefix line programmatically. It is not mentioned in the conda doc, except for the fact that conda env export –prefix PATH allows to specify a prefix. But note that –name … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)