conditional-statements

How do you identify a list of filepaths containing non-ascii characters?

How do you identify a list of filepaths containing non-ascii characters? Question: I would like to print a list of file paths from a Windows directory which contain non-ascii characters. The files are located on deeply-nested subdirectories. I have two pieces of the problem figured out: A conditional that can evaluate a character and determine …

Total answers: 1

Django views.py Exception Value: Could not parse the remainder:

Django views.py Exception Value: Could not parse the remainder: Question: I get an Exception Value error: Could not parse the remainder: ‘(column)’ from ‘item.get(column)’ views.py: def home(request): position = DjangoEmail.objects.get(Email=request.user).Position year_filter = Q(Year=now.year) | Q(Year=now.year-1) | Q(Year=now.year+1) if position == 7: data = Employee.objects.filter(year_filter, Mlkk=request.user).order_by(‘Year’,’OblastTM’).values(‘Year’, ‘OblastTM’, ‘Category’, ‘ProductGroup’,’NameChaine’).annotate(Januaru=Sum(‘January’)) elif position == 6: data = Employee.objects.filter(year_filter, …

Total answers: 1

changed_when: in Ansible

changed_when: in Ansible Question: I’m having trouble setting up the changed_when condition on a specific task on my playbook. I used to use ignore_errors: true in the past, using the git module: – name: Checkout in client folder ansible.builtin.git: repo: "{{ item.value.dev_repo | default(‘git@*****:***/****.git’) }}" key_file: /tmp/oci_odoo.rsa accept_hostkey: true dest: "/opt/odoo/odoo_{{ item.key }}/addons" version: "{{ …

Total answers: 1

Python – How do I return True for a positive number?

Python – How do I return True for a positive number? Question: I am attempting a practice question on Coursera where the code seems to be throwing me off even though the logic seems fine to me. I am a beginner trying to get my hand on the language but I am running into logical …

Total answers: 2

How do I formulate a conditional function

How do I formulate a conditional function Question: I am trying to formulate te the following functions in python and I want to plot them import matplotlib.pyplot as plt import numpy as np ss = np.linspace(300, 1000, 15) def PT3000(ss): if ss < 318.842719019854: PT3 = 4.602 + 37440.0/ss else : PT3 =-0.3 + 3600.0/ss …

Total answers: 2

Understanding the logic with conditions using return statement python

Understanding the logic with conditions using return statement python Question: I have the following exercise from codingbat.com: Given 2 int values, return True if one is negative and one is positive. Except if the parameter "negative" is True, then return True only if both are negative. So, when I was solving it, I’ve formulated a …

Total answers: 1

how to create a new column based on string from different columns

how to create a new column based on string from different columns Question: I have a dataframe look like this: type city 1 dki jakarta 2 jawa barat 3 jawa tengah 4 jawa timur 5 sulawesi I want to create a new column called city_group based on the city. dki jakarta, jawa barat: jabo, jabar …

Total answers: 1

How to only count valid inputs

How to only count valid inputs Question: I have a function that is supposed to take input, calculate the average and total as well as record count. The bug in the code is that: Even though I have added a try and except to catch errors, these errors are also being added to the count. …

Total answers: 3

Is there way to do conditional dictionary definitions in python?

Is there way to do conditional dictionary definitions in python? Question: I’m the author of Pythonizer, and I’m trying to convert this code from perl to python: %entity2char = ( # Some normal chars that have special meaning in SGML context amp => ‘&’, # ampersand ‘gt’ => ‘>’, # greater than # PUBLIC ISO …

Total answers: 2

How to define a function based on vaues of multiple columns

How to define a function based on vaues of multiple columns Question: I have a datafile as follows: Activity Hazard Condition consequence welding fire chamber high painting falling none medium I need to create a fifth column based on the values in the activity, hazard, condition, and consequence columns. The conditions are as follows if …

Total answers: 2