New answers tagged

1

Singletons Color has been written as a singleton. That's fine I guess, but it doesn't need the class machinery. All you're effectively doing is making an inner scope. (You're also missing defaults.) You could get away with a submodule called color whose __init__.py consists of RED: str = '' YELLOW: str = '' PINK: str = '' CYAN: str = '' GREEN: str = '' ...


2

Code Review: I don't like this as it gives you an extra level of indirection. struct json_array { std::vector<json_value> array; }; You can simply use another name: using json_array = std::vector; This gives you a specific name for the array and removes the level of indirection. Sure this is resonable: struct json_object { std::map < ...


4

TLDR: it can be done much more quickly and much more concisely, in 28 minutes end-to-end, and in 12 minutes when all XML are already on disk. The key trick: using the long rather than wide format for each data frame. There are two parts to your code: style and performance. Let me post my approach and comment on why I coded it like this. For imports, I ...


3

It is fine to write things out as you did, but you want to keep DRY(Dont Repeat Yourself) in mind. That is where defining your own methods/functions comes in when you wan to start cleaning things up. Starting with this: Math.floor(Math.random() * 50) + 3 Math.floor(Math.random() * 90 - 1) + 1 This can be put into its own function to calculate ...


3

Avoid doing explicit appends in your for loop and use dictionary (or list) comprehension instead; this makes it run more than 3x faster on my machine. That is, do something like def run(file, content): data = etree.parse(file) get_path = lambda x: data.getpath(x) paths = list(map(get_path, data.getroot().getiterator())) content = [ ...


3

Seems like it might be a good use for parallizing with the multiprocessing library. Something like this (untested): from multiprocessing import Pool # your other code goes here mypath = '/Users/marcelwieting/Documents/AllPublicXML' folder_all = os.listdir(mypath) def process_folder(folder): df_final = pd.DataFrame() mypath2 = mypath + "/" + ...


4

I can offer some tips for making your code more pythonic. General It's good practice to add a docstring for each module, class, and documented function. Imports io and json are unused. In the Tar.__extract method, the variable total is unused. class Tar not file_path or len(file_path) == 0: If the user inputs an empty string, not file_path is sufficient (...


1

I think that the call to argp_parse() in hcv_parse_program_arguments() is missing a pointer to the arguments struct. Looking at the main() function in the canonical Argp Example 3, we see that the argp_parse() function is passed a pointer to struct arguments arguments. int main (int argc, char **argv) { struct arguments arguments; /* Default values. */ ...


0

the only advice, that I can give you, is to separate the logic in multiple methods. This will make your method shorter and allow the code to be reused. Personally, I see two other methods. String readString(Reader r, Charset charset) throws IOException { ByteArrayOutputStream ostream = copyInputToStream(r); final ByteBuffer byteBuffer =...


10

In programming there is the general principle Don't Repeat Yourself (DRY). Your code is a lot of repetition of exactly the same pattern, with only the string changing. So, just put those strings into a dictionary, with the final variable name as keys: RECEIPT_ITEMS = {"cp_poi": "POI", "cp_terminal": "Terminal", "cp_merchant": "Merchant", "...


5

bugs Due to the extra : in the lines, POI and Datum are parsed incorrectly {'cp_poi': 'POI', 'cp_terminal': 'ABC123', 'cp_merchant': '123456', 'cp_period': '1234', 'cp_transaction': '12345678', 'cp_card': 'xxxxxxxxxxxxxxx1234', 'cp_card_serial_number': '0', 'cp_date': '01/01/2020 04', 'cp_authorisation_code': '123ABC', 'cp_total': '1,00 EUR', '...


Top 50 recent answers are included