I’m new to Python and getting used to these really handy implicit array/list actions, so please bear with me. I’ve completed a proof-of-concept code (120 combinations), but as expected it is experiencing a significant slowdown when working against the full dataset (4 million combinations). The cur…
Passing dictionary values to a function, with missing keys
I have a class with a constructor that receives several arguments. These arguments I get from an external file, which is a list of dictionaries. My problem is that some dictionaries have missing fields. If a field is missing, I want the constructor to simply receive None instead. But as the code is written no…
How to return a search result with multiple books using the Google Books API?
I’m consuming a Google Books API and I’m trying to return a search result with multiple books. Here’s what I’m doing: Of course, this only returns one result. However, if I try to call it this way: It doesn’t return anything. Example of JSON to be consumed. How do I receive all r…
How to save a full size image with RGB and float32?
I have an image array with RGB, np.float32, and values in the range of 0 … 1. When I multiply the array with 255, and use cv2.imwrite, the output is not correct. When I use plt.imshow(img.astype(np.float32)), the output is right, but the image size is too small. How can I output a good image? Answer The…
Wrong result with regular expressions
Any idea why the regular expression below cuts the ‘fl’ part of the sentence ? This is the result I get : Answer You’re replacing all non-alphabetical characters with whitespace. In your code, the ‘fl’ is actually fl – a single unicode (non-AZ) character, so it is being remo…
Strange gzip – almost extracted, but not totally correct
Some program sends some info that starts with x1fxe2x80xb9x08x00x00x00x00x00x04x00M… to the server and receives the text response. I need to guess what info is it. In fact, I need the method to convert the real string to that identical gzipped original string to receive responses without that program. A…
Access attributes in JSON file with python and filter items which attribute matches to specific value
I have JSON file (list.json) as an input: I am trying to extract all modules (their names) if “Vendor” matches to some criteria, in this case all of the modules with “Vendor”: “comp” should be printed (Module2, Module3). My code is: import json When I run this code, I keep …
filter even and odd values from a dictionary and add these even and odd values to lists and write them to a txt file
code: error: name ‘odd’ is not defined Is it not found because it is empty in the lists but I add even and odd number. I do not understand why you gave such an error.How can i fix error? Answer Variables have a scope. If they are in a method, the variables are gone when the method is finished. Tha…
Converting list to comma separated integers to be substituted in IN clause of Pandas dataframe query
I have a list of integers that contains EMPI_ID I have a variable that defines the SQL query Columns for the dataframe: When I try to convert them to comma separated integer values, the sql_string hold Str values and is failing to fetch the data from database. Please advise how i can change the query to subst…
Django Error: Field ‘id’ expected a number but got ‘list’
I have an app with 2 models and I’m trying to create a List View and a Detail View. The list view worked fine, but when I created the detail view the list view stopped working and it’s prompting me with this error: “Field ‘id’ expected a number but got ‘list’. Models.…