Space in f-string leads to ValueError: Invalid format specifier

Advertisements A colleague and I just stumbled across an interesting problem using an f-string. Here is a minimal example: >>> f"{ 42:x}" ‘2a’ Writing a space after the hexadecimal type leads to a ValueError: >>> f"{ 42:x }" Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: Invalid format specifier I understand… Read More Space in f-string leads to ValueError: Invalid format specifier

is const variable in javascript function initialized every time when it called or just once?

Advertisements I’d like to code something like this. function cokeDispencer(id) { const dict = {1:"sprite", 2:"pepcy", …} // Some JSON. It might be bigger. return dict[id]; } Of course, dict[id] is much simpler way to do the same, but I want put the dict object inside of function so that no other function can access… Read More is const variable in javascript function initialized every time when it called or just once?

Python Class – Can't find out how to use method return value within another method

Advertisements So this is the class i’m testing: class Test: def find_string(self, string): self.string = string return string.find(string) def add_string(self, string): found = self.find_string(‘bar’) if found == -1: string = string + ‘ bar’ return string Here is my setup: test_string = ‘foo’ Test1 = Test() new_string = Test1.add_string(string) Results Expected result: foo bar Result:… Read More Python Class – Can't find out how to use method return value within another method

Python pandas: dynamic concatenation from get_dummies

Advertisements having the following dataframe: import pandas as pd cars = ["BMV", "Mercedes", "Audi"] customer = ["Juan", "Pepe", "Luis"] price = [100, 200, 300] year = [2022, 2021, 2020] df_raw = pd.DataFrame(list(zip(cars, customer, price, year)),\ columns=["cars", "customer", "price", ‘year’]) I need to do one-hot encoding from the categorical variables cars and customer, for this I… Read More Python pandas: dynamic concatenation from get_dummies

Python readibility of long statement

Advertisements I have a call to a function which returns a lot of elements, and the way to respect PEP8 is to do the following, but I don’t find it very readable: colonne_dernier_attribut, colonne_non_explained_beads, colonne_non_explained_beads_recipient, \ colonne_non_explained_beads_donor, colonne_score, colonne_comments, colonne_loci_manquants, \ colonne_edta, colonne_temps, colonne_summary = \ formatageRes(ws, wrsep, wdsep, feuille, feuille_corrigee, all_epitopes_considered, nbr_ep_considered, nrows) I… Read More Python readibility of long statement