New answers tagged

3

It is generally serialized because serialization is the lowest common denominator, thus it is the easiest thing to code to and verify. When this becomes a limitation, you can look at your specific problem and see if there is a better solution. For example, if the large data objects in Python are actually numpy arrays, numpy exposes its internals with a C ...


1

I'm at that exact same situation you seem to be. We're decided on HTTP for the majority of the app and WebSockets to handle more real time interactions. We're keeping as much in the HTTP side of things as we can. But the majority of the essencial features are handled over a websocket connection using transactional state management (see flask-sockets). ...


2

The OOP solution is interface segregation. All rule functions you have should accept an interface exposing the methods and attributes they need to function. This allows client code to decide on a given implementation. While beeing very clear on what the rules need to function. Let's say. from abc import ABC def rule_1(input: Rule1Input) -> bool: pass ...


-1

You can get what you want by using this way, sending a request to the target page and retrieving the content of the page, then searching for the element that holding the copyright text, in this case it's an div element with the class name footer, then get the text of the element, remove all the whitespaces from left to right, splitting into a list of spaces, ...


2

Figure out where speed is actually needed. Rewriting all your code is almost certainly not necessary as it is only going to be in a few places (likely) where speed is really needed. Also remember that many attempts to increase speed would be more appropriately solved with things like a queue. You can create wrappers to just run the Python code from your C++ ...


-1

So, after some more searching, I believe I have found tools for my needs. They parse YAML files and have the benefit of... ... throwing errors early on IF the yaml file is wrong ... providing default arguments ... being tied closely to the code (and thus git commits) in contrast to the yaml file. https://github.com/rbgirshick/yacs https://github.com/omni-...


1

I would recommend you go with the second option: Use Flask for the API and use a javascript framwork like React for the UI component. See seperation concerns (on wiki and stackexchange) for more information about this. The reason for this is that Flask is good for API related tasks and React is good for UI related tasks. Once you start trying to get Flask to ...


2

If the two sites offer essentially the same services on behalf of a single organisation to two different audience groups and the difference between the sites is mainly in branding and some supplementary features that makes each site more attractive to its respective target audience, then you should aim to use shared components as much as possible. That would ...


0

Keeping a clear dependency graph is a good thing, because the results can be a bit unexpected when two modules import each other. However: Only importing child modules is probably a bit restrictive. You might have one module that is imported by many other modules. Only importing child modules will likely require doing a lot of dependency injection to make ...


0

One counter-example is when you use a function to reset properties, avoiding duplicated code: class Handler(object): def __init__(self): self.resetProperties() def resetProperties(self, prop1=None, prop2=None): self._prop1 = prop1 self._prop2 = prop2


-1

Yes. Use a type checker and PEP 484 type hints.


0

I'd prefer extracting the complex condition to a function. Why? By introducing well-named classes, methods, functions and so on, we create the application-specific language that we want to express our solution in. Being able to just call has_three_repeated_digits(some_number) serves that goal better than filling multiple lines of code in the higher-level ...


2

There are no hard rules for when to extract boolean conditions into their own function. It depends a lot on the logic happening in the code, how much code there is in the method, how readable the code is, if you need to reuse the condition some place else, etc. If you need the same conditional check in multiple places, then the answer it pretty much straight ...


0

You said you use such computed boolean variables for avoiding redundancy and improving readability. So, instead of computing it again and again you just compute it once, store it, and use it as required. The same logic needs to be applied when deciding whether to use a variable or a function. The goal is to make the code non-redundant and, as a result, ...


2

The answer is (as usual) that is depends. If this data is going to be used for reporting and especially ad-hoc reporting, you probably want to pull the variables out into a proper relational model. Another reason might be if you need to expose that data in multiple formats. If you don't need to do any of that then the option of keeping the documents as-is ...


1

The first thought I have here is that you might be able to solve your problem with better error handling. An approach I have used recently for a similar problem was that I use the get(key, default) method on dict for optional parameters. For required parameters, you could simply use the dict[key] syntax and put a helpful error message in the except KeyError ...


0

Playground is a dictionary. Linters tell you to make that explicit. It will help to understand the program later.


1

The type systems of Python on the one hand and C# and Java on the other hand work in a fundamentally different way. C# and Java use a nominal type system: Two types are the same if they have the same name. Additionally, they use strong typing: assignment (and parameter passing) between references is only allowed if the target type is in the set of types ...


2

I would put an interface in front of the dictionary and disallow the addition of generators named the same thing as one of the framework generators.


3

LSP means that if you have an instance of a subclass, it can be used in place of an instance of the base class. Creating an instance of a subclass is not subject to LSP, since there is no complete instance yet. Thus, LSP only means the instances must be substitutable. The classes do no have this restriction.


Top 50 recent answers are included