Комментарии:
I once was creating a parser in python and, naturally, was using bs4 for finding stuff. This, however, resulted in a bottleneck and replacing bs4 with regex made a 12x speed improvement from a couple of seconds for each operation to a couple dozens of milliseconds
ОтветитьMy takeaway as a non-python programmer: Oh dear god, python has support for multiple inheritance.
ОтветитьThis is Good Stuff! 17 years of assembler followed by 20+ years of C have left me unprepared for these newfangled gadgets. Thanks ever so much for helping me see through the blur ....
Ответить#11 I don't actually like @property, when someone creates a setter it usually has a side effect. If I'm looking at where it is used, `obj.x = something` it is really surprising when I find out that this does something more than just changing the x variable. But if I see an `obj.set_x(something)` that immediately raises the alarm: `set_x()` probably does something more - why would anyone bother to write this function otherwise?
I suppose if your setter really has no side effect it is safe to use property, but in my experience that is rare (maybe you want to log where it changed or something like that, it's fine). Usually however, it re-computes related values or notifies other objects that a value has been updated - you should be aware of these.
What's the benefit of StringIO over a list and "".join(the_list)?
Ответить"Concatenating strings with plus" I doubt it gives a meaningful performance improvement if you have string concatenation once or twice in a program. Sure, when I will be writing extra long strings I might actually use this, otherwise it's just unnecessary code obfuscation.
Ответить+1 to #9: "Using single letter variables". For real: nobody is going to understand what is meant by x or y or t or v.
PSA: USE DESCRIPTIVE VARIABLE NAMES!!! It takes one second longer to type out a descriptive variable name and your future self will thank you when you come back months later to read your code and wonder, "Why the hell did I call this 'x'? What does 'x' mean in this code?"
Do the separators matter in pathlib? I always use os.path.join to create the path string, since I have no idea if / will be translated to \ on vomits Windows.
The variable thing is very common amongst scientists who use Python. I find a lot of them write Python as they would C. We had a science staff member writing incomprehensible code with variables named iptr which in his mind, meant index of partner. slaps head Reading his code was hard enough because we software engineers weren't familiar with the scientific formulae in that branch of science, so I would just go through and change all the variable names after he merged a PR because it was faster than asking him to do it.
He would also use dictionaries to pass everything around and had to be taught dataclasses. Thank the Python gods for dataclasses.
#3 paths as strings, and even recommends Pathlib instead of os.path
#17 „defines path as raw string“
Eh?
captions are a little JANK...
ОтветитьPygame does.#21
ОтветитьHow does he highlight in blue?
ОтветитьTo add onto the one-letter variable names: if you want to use multi-cursor on the variable later, you're boned because that one letter shows up all over the place.
ОтветитьSometimes, even after 8 years of python, you have some nooby habits :) . As always great video !
Ответить# Long_computation... 42. Love it xD
ОтветитьOn #5, searching for answers gives some mixed messages, where the immediate evidence is that += is faster than the alternatives in most cases due to some python interpreter trickery, but in testing it's pretty clear that io.StringIO is substantially faster. For 50,000 appends I get 0.00428s using perf_counter, and with StringIO I get 0.00299s. That enormously faster.
ОтветитьMore people need to know about ast.literal_eval(), as it will probably do what you want from eval() while being completely safe.
ОтветитьHola! Puedes explicar él biblioteca io? Gracias. Saludos de Brasil.
ОтветитьAs far as I know, something was changed in string concatenation. Concatenation of 10 million elements with StringIO beats basic string concatenation just by 10%
Ответитьgood ones. i see no point abt map/filter tho.
Ответитьi noticed that for #15 the first line was actually line 15, and i think it would be a neat little easter egg if the first visible line would always match the current number.
Ответить