python-2.x

Printing not being logged by Kubernetes

Printing not being logged by Kubernetes Question: I have simple python 2.7 program running in container off Kubernetes (AKS) which is printing debug information to standard output response = requests.post(uri,data=body, headers=headers) if (response.status_code >= 200 and response.status_code <= 299): print ‘Accepted ‘ + log_type + ‘ on ‘ + rfc1123date else: print “Response code: {}”.format(response.status_code) …

Total answers: 2

Making a calculator in python

Making a calculator in python Question: So i Tried using this chunk of code to create a calculator in python, since I have just started learning. Thing is, it always says I enter an invalid option, passing through all my if-else statements, even when I do enter a valid option. What did I do wrong …

Total answers: 3

no module named cairo – python and pip

no module named cairo – python and pip Question: I am trying to build openuds and I get the error no module name cairo, I surfed a bit and found installing pycairo will solve it. 1) How do I fix this install error? python manage.py createcachetable Traceback (most recent call last): File “manage.py”, line 9, …

Total answers: 2

How to get the maximum value of a dictionary tuple

How to get the maximum value of a dictionary tuple Question: I have a dictionary like this: dic={(0, 1): 0.059999999999999996, (0, 5): 0.13157894736842105, (0, 15): 0.23157894736842105, (1, 0): 0.049999999999999996, (5, 0): 0.13157894736842105, (5, 15): 0.049999999999999996, (15, 5): 0.23157894736842105} I would like to get the maximum value for each element in the first coordinate of the …

Total answers: 3

Recursive vs Iterative Functions Python

Recursive vs Iterative Functions Python Question: I am currently learning Python and would like some clarification on the difference between iterative and recursive functions. I understand that recursive functions call themselves but I am not exactly sure how to define an iterative function. For instance, I wrote this code random_list = [‘6’, ‘hello’, ’10’, ‘find’, …

Total answers: 4

Product of multiple lists–individual lists vs array of lists, need help understanding

Product of multiple lists–individual lists vs array of lists, need help understanding Question: Forewarning: I’m new to Python and I’m teaching myself, so this question may just have a trivial solution–any help (and patience) is very much appreciated! Okay, big picture is that I want to get the union of all possible intersections of a …

Total answers: 1

map in Python 3 vs Python 2

map in Python 3 vs Python 2 Question: I’m a Python newbie reading an old Python book. It’s based on Python 2, so sometimes I got little confused about detail. There is a code L=map(lambda x:2**x, range(7)) so it doesn’t return the list in python 3, and I googled it and found that list(L) works. …

Total answers: 2

f-strings giving SyntaxError?

f-strings giving SyntaxError? Question: I tried this code, following along with a tutorial: my_name = ‘Zed A. Shaw’ print(f"Let’s talk about {my_name}.") But I get an error message highlighting the last line, like so: print(f"Let’s talk about {my_name}.") ^ SyntaxError: invalid syntax Why? If you get an error like this from someone else’s code, do …

Total answers: 7

How do I parse a yaml string with python?

How do I parse a yaml string with python? Question: I see an API and many examples on how to parse a yaml file but what about a string? Asked By: gae123 || Source Answers: Here is the best way I have seen so far demonstrated with an example: import yaml dct = yaml.safe_load(”’ name: …

Total answers: 2

Appending user input in a list

Appending user input in a list Question: I run into a problem with the 2nd and 3rd if statement. It does seem to register input but it’s not adding it to list. You can observe the problem I’m talking about if press 2 add product and press 1 for listing products. You will notice that …

Total answers: 1