My main model class looks like this: And, for my api to send backend data to front end, I have a serializers class that looks like this: Clearly, the current way of writing fields as a bunch of hard-coded strings is very clumsy and prone to mistake (since I might change the fields in Article class but forget to update
Tag: coding-style
how can I refactor or friendly programmer view? [closed]
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago. Improve this question I want to convert this into a more readable for other programmers in the team, but I am not sure how
What does it means to not exceeding 80 characters in a line in Python?
There is a mention that it is preferable for that a line in a Python script should not exceed more than 80 characters. For example: Does it include the characters of the print function, the strings (including spaces), parenthesis etc.? And does it not limited to other functions besides print? What is the reason behind this? Already googled for answers
How to copy a dict and modify it in one line of code
Very often I need to create dicts that differ one from another by an item or two. Here is what I usually do: The fact that there is a point in the program at which setup2 is an identical copy of setup1 makes me nervous, as I’m afraid that at some point of the program life the two lines might
How to break a line of chained methods in Python?
I have a line of the following code (don’t blame for naming conventions, they are not mine): I don’t like how it looks like (not too readable) but I don’t have any better idea to limit lines to 79 characters in this situation. Is there a better way of breaking it (preferably without backslashes)? Answer You could use additional parentheses:
Is there a way to iterate a specified number of times without introducing an unnecessary variable?
If I want to iterate n times in Java, I write: In Python, it seems the standard way to do this is: As always, Python is more concise and more readable. But the x bothers me, as it is unnecessary, and PyDev generates a warning, since x is never used. Is there a way to do this that doesn’t generate