All Questions
219 questions
4
votes
2
answers
121
views
Managing file paths in a python Data Science project
When doing Data Science projects, I often have to load data and metadata, and output results, plots, logs, etc.
Therefore I have to handle all the file paths from where to load the input and write the ...
5
votes
2
answers
102
views
Accessing and editing a database in python using JSON
I am a beginner programmer and have recently started learning python. I wrote this code as a little project to understand dictionaries better and ended up having to learn to use JSON. I am self-taught,...
-2
votes
1
answer
91
views
Initializing an object using a staticmethod
I've an object that looks like this, and users have been populating the attributes post-initialization, e.g.
...
6
votes
2
answers
713
views
What is the best way to set a class value to a variable in Python if it exists in a dictionary?
I have this code which sets values in a location class from values from JSON data.
...
3
votes
1
answer
175
views
parsing json file with potential corrupted record and sorting by id to output first n lines - cleaner logic
messy json file is parsed and should output the N highest
record IDs & scores by score in descending order, highest score first.
the code works but i wonder if there is better readability, help me ...
3
votes
1
answer
993
views
"Fixing" broken JSON with unescaped quotes
This code is supposed to fix JSON structures that are broken by having unescaped quotes in strings and try to recover if possible.
The code can only recover on certain cases and can be fooled by ...
2
votes
0
answers
156
views
Python raw dataclass to formatted dataclass transformation for avro schema
I receive some data from an api. I would like to define the raw responses schema and model it as a python dataclass, with the added benefit of using the ...
2
votes
0
answers
138
views
Python code to add GeoIP data to a Suricata eve.json log
I wrote this script as part of a Suricata course where I had to annotate destination IP addresses with GeoIP data in an EVE JSON log file.
I would like your input on my code style and smell, ...
3
votes
1
answer
63
views
Optimizing code for this function that filters a JSON file
I made a function that turns all child from a JSON file to parents (or brothers?). It adds the parent name to the key, so there are no duplicates.
It works ok, but I would like to ask if there are ...
2
votes
1
answer
90
views
Implementation of JSON schem parser to extract some attributes
I have three different types of schema possibilities as below:
...
1
vote
1
answer
58
views
Iterating over JSON more effectively
Problem:
I need to get data from JSON file containing information about "contributors". Each contributor has an atrribute jobs, which is a list of string-...
3
votes
2
answers
105
views
Saving and reading the last successful execution as a json-file
I've got some tools that run perdiodically like weekly or monthly that don't support any retry mechanism. In order to increase their chance to succeed in case a database wasn't reachable or some other ...
4
votes
1
answer
78
views
Generating a randomized JSON for testing RabbitMQ
The following code will be used to generate a random json object to be used as a RabbitMQ message body. The code works but I'm sure it can be improved in ways that I am not seeing, as I am a novice.
...
3
votes
1
answer
448
views
Deterministically hash dictionary
I need to compute a deterministic hash for a JSON-serializable dictionary.
This answer almost does the job, but there are a few problems.
If dict1 == dict2 then I ...
6
votes
1
answer
1k
views
Elegantly combine list of records into JSON for a Python post request?
I'm parsing a Pandas DataFrame table for an API post request (using requests, of course). I'm working on building my script in Jupyter Notebooks.
...