21 MORE nooby Python habits

  Рет қаралды 112,035

mCoding

mCoding

Күн бұрын

Get better at Python by ditching these habits.
Embrace the Zen of Python and leave your nooby habits behind! Improve your code and your prestige and learn how to master Python.
CONTEST CURRENTLY CLOSED!
OFFICIAL CONTEST RULES:
1. All entries must comply with the KZfaq community guidelines ( kzfaq.infocommunity_gu...) and KZfaq Terms of Service (kzfaq.info?gl=US&t.... Entries that violate KZfaq guidelines are automatically disqualified.
2. KZfaq is not a sponsor of the contest and viewers are required to release KZfaq from any liability related to the contest.
3. Privacy notice: no personal data will be collected for this contest.
4. In order to enter, you must (a) be one of my subscribers, AND (b) make a top-level comment to the video including #pycharm somewhere in the comment.
5. The contest is free, there is no fee required to enter.
6. Winners will be chosen randomly 1 week after the date the video went live from all users who have entered and not been disqualified.
7. Each winner will be notified via a comment reply from me that details what prize was won (e.g. "Congratulations! You have won XYZ. Please email me."). I will ask the winner to contact me by email, and I will reply through email with a random token which must be posted as another reply to the winning comment from the winning account in order to verify account ownership and prevent fraud.
8. Each winner will have 72 hours to respond AND prove account ownership or their prize is automatically forfeited and another winner will be chosen.
9. A winner can only win 1 prize per contest.
10. The prize pool for this contest is: 2 licenses ("Free 1-Year Personal Subscription") to any of these JetBrains IDEs: AppCode, CLion, DataGrip, DataSpell, GoLand, IntelliJ IDEA Ultimate, PhpStorm, PyCharm, ReSharper, ReSharper C++, Rider, RubyMine, WebStorm, or dotUltimate. A prize consists of 1 license, which will be delivered in the form of a redeemable code that can be redeemed at www.jetbrains.com/store/redeem/ before May 17, 2023.
11. You may not enter the contest if doing so would be a violation of any relevant federal, state, and local laws, rules, and regulations, including U.S. sanctions.
― mCoding with James Murphy (mcoding.io)
Source code: github.com/mCodingLLC/VideosS...
Previous Nooby habits video: • 25 nooby Python habits...
Super video: • super/MRO, Python's mo...
def main if name main idiom video: • You should put this in...
Descriptors and properties video: • 8 things in Python you...
SUPPORT ME ⭐
---------------------------------------------------
Sign up on Patreon to get your donor role and early access to videos!
/ mcoding
Feeling generous but don't have a Patreon? Donate via PayPal! (No sign up needed.)
www.paypal.com/donate/?hosted...
Want to donate crypto? Check out the rest of my supported donations on my website!
mcoding.io/donate
Top patrons and donors: Jameson, Laura M, Dragos C, Vahnekie, Neel R, Matt R, Johan A, Casey G, Mark M, Mutual Information
BE ACTIVE IN MY COMMUNITY 😄
---------------------------------------------------
Discord: / discord
Github: github.com/mCodingLLC/
Reddit: / mcoding
Facebook: / james.mcoding
CHAPTERS
---------------------------------------------------
0:00 Intro
0:28 #1 Manually rounding in a print statement
0:45 #2 Repeatedly converting to and from numpy arrays
1:06 #3 Manipulating paths as strings
1:27 #4 Only providing io functions taking a path
2:07 #5 Concatenating strings with plus
2:31 #6 Using eval as a parser
2:59 #7 Storing function inputs/outputs as globals
3:20 SELF PROMO!
3:30 #8 Thinking and/or return bools
3:51 #9 Too many single letter variables
4:16 #10 Using div and mod instead of divmod
4:32 #11 Not knowing about properties
5:11 #12 Expensive properties
5:35 #13 Inserting/deleting while iterating
6:07 #14 Any use of filter or map
6:42 #15 Defining too many dunders
7:07 #16 Trying to parse html/xml using regex
7:39 #17 Not knowing about raw strings
7:57 #18 Thinking super means parent
8:32 #19 Passing structured data as raw dict or tuple
8:53 #20 Using namedtuple instead of NamedTuple
9:11 #21 Import-time side-effects
9:33 Outro

Пікірлер: 636
@markolson8569
@markolson8569 Жыл бұрын
Love the "don't parse HTML with regex" reference. One of my favorite pieces of programming humor.
@notenoughmonkeys
@notenoughmonkeys Жыл бұрын
For #17 there is a minor gotcha being you can't end a raw string with a lone backslash (i.e. r"windows\path" is legal, r"windows\path\" is not). Trivial to workaround but something that might catch people out the first time they try to prepend with r.
@DanCojocaru2000
@DanCojocaru2000 Жыл бұрын
That's a very weird restriction.
@notenoughmonkeys
@notenoughmonkeys Жыл бұрын
@@DanCojocaru2000 So it makes sense when you realise it’s not a raw string, it’s a string with the escape sequences left unparsed. But they still have to be legal escape sequences. So “abc\” isn’t legal because it assumes \” is the unescaped text and the string is now missing the closing quote. It’s also why “abc\\” is legal.
@DanCojocaru2000
@DanCojocaru2000 Жыл бұрын
@@notenoughmonkeys Quite weird design.
@notenoughmonkeys
@notenoughmonkeys Жыл бұрын
@@DanCojocaru2000 Completely agree. Caught me completely off guard when I first encountered it, but once you know, you know.
@taravanova
@taravanova Жыл бұрын
Not the first time I've prepended with r, but this actually happened to me today and I couldn't see why it shouldn't work. What a timely coincidence.
@atrus3823
@atrus3823 Жыл бұрын
I agree about map and filter. Comprehensions are usually more readable and avoid ugly function expressions, but there is a niche use case for map: if your generator comprehension would look like this: (f(a, b, c) for a, b, c in zip(A, B, C)), map(f, A, B, C) is a lot more elegant, and often more readable. For example, (a + b for a, b in zip(A, B)) becomes map(add, A, B). (need to import add from operator)
@thirtysixnanoseconds1086
@thirtysixnanoseconds1086 Жыл бұрын
idk see anything wrong with map(int, arr) tbh
@cleverclover7
@cleverclover7 Жыл бұрын
idk, at returning and passing in 3+ tuples you really should start thinking about using a namedtuple at that point imo
@atrus3823
@atrus3823 Жыл бұрын
@@thirtysixnanoseconds1086 yeah, that's another good use for map. I guess I should have said there are few niche use cases for map.
@atrus3823
@atrus3823 Жыл бұрын
@@cleverclover7 none of these examples are returning 3 tuples. They all return iterators. Can you elaborate on the use of named tuples here?
@Deadlious
@Deadlious Жыл бұрын
not to mention that in certain situations map is a tiny bit faster...
@p3ol
@p3ol Жыл бұрын
I started learning python a couple years ago to fill a gap left by depression. I'm close to 50 now (not that I wasn't 2 years ago), in that time I've managed to write an AOL3.0+ compatible server - for nostalgia - in python utilizing your videos for guidance, and other content creators as well. I've recently switched to using #pycharm from vscode. Thank you very much for your content, it has helped me tremendously in improving my project and my comprehension of python.
@neverchesterfield
@neverchesterfield Жыл бұрын
Congratulations for your hard work!
@stacklysm
@stacklysm Жыл бұрын
Thanks for making a sequel to the first Nooby Habits video, would be awesome if you could do another one for C++ as well.
@DanielLavedoniodeLima_DLL
@DanielLavedoniodeLima_DLL Жыл бұрын
I've just found out that I never really understood the behavior of "and" and "or" for non-boolean types before this video. Awesome content, as always! #pycharm
@nnirr1
@nnirr1 Жыл бұрын
Awesome tips! Love your videos ☺️ Personally I prefer to iterate over a copy of the dict instead of the extra for loop. While it's less memory efficient, I don't mind it too much since it's a shallow copy and in most cases, I prioritize the readability of the code over efficiency. Also, I'm a bit torn on the filter and map tips (well, less on the map part and more on the filter part 😉) When there is no lambda involved, and depending on the specific variable names we are working with, the filter function can sometimes be closer to human language (though I admit this doesn't happen often). I wonder if in the future there will be a clear runtime difference between the two, there is already a PEP open to make comprehensions more efficient. #pycharm
@hankertric
@hankertric Жыл бұрын
I love the “and” and “or” explanation, it’s so much easier to understand compared to all the resources out there on the web that have some convoluted explanation of it that’s really difficult to understand. #pycharm
@mihaitranda8228
@mihaitranda8228 Жыл бұрын
Great tips, man! One of my favorite channels. Keep up the good work. #pycharm
@lennartbreede
@lennartbreede Жыл бұрын
pathlib is definitely something I could be using more and StringIO was completely new to me! Thank you, love your content #pycharm
@evansuits4926
@evansuits4926 9 ай бұрын
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 ....
@belug23
@belug23 Жыл бұрын
I'm happy that I've learned a few things again here, it's not always being new at the language that makes you do less optimal stuff. sometimes it's being old at it. Format strings are, for me, fairly recent, I know they've been here for years, but I've been coding python for way longer than they've been here, and it's not always easy to let old habits die and to make sure you know exactly all the new ways to do things in the new version you're starting using, at least I've been using format strings, but now I'll have a look into the doc for those extra formating parameters to up my game a little. And thanks for the io.stringio trick, I didn't knew that one before. #pycharm
@v2ike6udik
@v2ike6udik 5 ай бұрын
Old habits be like *dr_who_in_da_rain.gif"
@Max-mx5yc
@Max-mx5yc Жыл бұрын
Love your channel! Have you considered making a video on 'async for' and 'async with'?
@spacebibba8984
@spacebibba8984 Жыл бұрын
Regarding #14: Mostly, one should go for generator expressions like you did, as wirting out "lambda x: ...." as function doesn't save many characters and makes the thing harder to read - granted. However, When stacking multiple of those expressions (map, filter, reduce, etc.), they can be quite cool. Especially when all those variable names used in your generator would happen to be longer than the usual line together (so you're force to line-break), it looks cleaner to line-break between arguments of a function (effectively creating an easily traceable staircase of transformations functions) that to line break before the "if" of a generator - the latter looks much uglier when stacked into each other. One could argue that I should define my generator expression, then use it when defining the next generator expression and so on, until I did all my transformations - fair point. However, this encourages defining multiple useless variables which serve so purpose and uses up the same amount of lines a stacked reduce(sum(map(fm, filter(ff, myList))) does. I agree, that real use-cases with enough transformations to make this worthwhile are rarer that isolated cases of a map for filter transformation. When confronted with the latter, you should obviously choose the generator-expression approach.
@joshix833
@joshix833 Жыл бұрын
For that I'm currently writing a library. That'll help to handle this nesting mess without needing to define many variables. It's typed-stream on pypi. It's usable, but hasn't reached 1.0 yet. e.g.: Stream.counting().limit(100).map(operator.mul, 2).filter(lambda x: x%5).peek(print).sum()
@karserasl
@karserasl Жыл бұрын
So... Functional programming?
@cleverclover7
@cleverclover7 Жыл бұрын
Totally agree with all of these, but the 2 that irk me the most is altering the iterator and using eval. There's almost always a better way to do it than to use eval, but I think in the age of computer generated code it's especially important to understand the dangers of.
@yolosaurusrex90
@yolosaurusrex90 Жыл бұрын
been programming in python for years and consider myself somewhere between intermediate and advanced, and even your beginner-oriented videos have something new to me in them. there are so many beginner python creators out there and i'm thankful that it's so accessible now, but i definitely appreciate the higher-level "niche" you tend to make videos in, even when you claim it's for noobs. also #pycharm gimme that license mDaddy
@Higgsinophysics
@Higgsinophysics Жыл бұрын
omg you actualy a solved a python issue I am currently facing lol. Always a greeat watch. Thank you :D
@Libertarian1208
@Libertarian1208 Жыл бұрын
#13 deleting while iterating - one can use for key, val in list(d.items(): del d[key] In fact you have shown this in one of your videos and I have been using that ever since. It makes code much more readable that collecting the things to delete. #pycharm
@cetilly
@cetilly 5 ай бұрын
This is a gem! I love this
@baryemini4103
@baryemini4103 Жыл бұрын
I personally usually prefer filter or map if possible over list comprehensions, I think filter and map have quite an unfortunate syntax in python, as at least in my opinion the order is completely flipped compared to how you read it, I read it as “iterator, operation, function” and instead it reads as “operation, function, iterator”. This also means chaining them is a nightmare because it’s nested instead of appearing one after another, and neither one is ergonomic nor readable when chaining more than two… also the lambda syntax is overly verbose, and not particularly accessible especially to non native speakers as it’s quite an obscure word
@andrewglick6279
@andrewglick6279 Жыл бұрын
I agree that map and filter's syntax in Python isn't the best. As much as I like list comprehensions, sometimes I find myself wanting to use map or filter, but I'm not a huge fan of Python's lambda syntax. I wish there were a better way to do multi-line inline functions in Python (plus don't even get me started on the Callable[] type hint). You might appreciate the PyFunctional library which adds a convenient way of chaining map/filter. Unfortunately, it doesn't currently have support for type hints so it's maybe not the best if you use Pylance's type checker.
@joshix833
@joshix833 Жыл бұрын
I'm currently writing a library called typed-stream. That allows you to easily chain such operations. It's fully typed and checked with mypy
@srenbzr
@srenbzr Жыл бұрын
Not sure about avoiding map/filter all the time but awesome tips, thanks #pycharm
@Nerdimo
@Nerdimo 3 ай бұрын
I’ve coded python for about 3 years now and never knew divmod existed. I learn something knew every time I watch your channel
@cristianbitica8204
@cristianbitica8204 Жыл бұрын
thanks mate, pretty useful information, some of these I’ve been doing myself, some I didn’t even know about. keep going with this great content. #pycharm
@bp56789
@bp56789 Жыл бұрын
These videos are a huge help, man. Thank you. #pycharm
@iloveudead
@iloveudead Жыл бұрын
Thanks for all the work you do, always enjoying! #pycharm
@jannis.wagner
@jannis.wagner Жыл бұрын
As always very high quality content. I love it. Keep it up 👍 #pycharm
@justingerber9531
@justingerber9531 Жыл бұрын
3: I'm ALWAYS trying to tell people to use pathlib.Path instead of strings!! 10: Ooh divmod looks awesome! Can't wait to use it! 14: Interesting take on filter/map, I think I could agree. 17: I *roughly* knew about raw strings but feel more confident with them after you're 20 second explanation (which I watched at 2x speed) 21: Yes, forcing prints at import is the worst!! Love all your videos, thank you! #pycharm
@lawrencedoliveiro9104
@lawrencedoliveiro9104 Жыл бұрын
pathlib just seems to be a sop to Microsoft Windows. String manipulation is perfectly straightforward for POSIX paths. 7:45 Fun fact: “/” works as a path separator even on Python on Windows.
@justingerber9531
@justingerber9531 Жыл бұрын
@@lawrencedoliveiro9104 I've never worked in a pure POSIX environment, and now I work in an environment where code is deployed on both Windows and Linux systems. I don't know the difference between all different types of forward and backward slashes and which operating systems uses which types in which cases and that's the way I want it.
@slash_me
@slash_me Жыл бұрын
​@@lawrencedoliveiro9104 it's fine, but still pathlib is very convenient, it helps with splitting paths into their components and has a nice functional interface that allows chaining. Also, it helps a lot if you need to handle paths that need to follow specs of a foreign OS (handling POSIX paths in Windows or vice versa).
@lawrencedoliveiro9104
@lawrencedoliveiro9104 Жыл бұрын
@@slash_me Everything does POSIX these days. It’s no point developing for anything else.
@slash_me
@slash_me Жыл бұрын
@@lawrencedoliveiro9104 not true. I had a case recently where I needed to handle Windows paths on a POSIX system and pathlib was perfect for that. No, I couldn't use POSIX paths, I explicitly needed Windows paths.
@SPARCHE
@SPARCHE Жыл бұрын
I experimented with concStringPlus and concStringIO and got a result that, at first, contradicted your assumption, since for small and non-chaotic strings the plus method is faster. So I added some complexity to the strings and the numbers got crazy for the plus, jumping from 0.55s to 1.61s, while remaining the same for the StringIO func (near 0.61s for 100000 runs with 100 operations each). My conclusion is: if you're incrementing your string with very small parts, stick to +=. If it's random-sized or chaotic, StringIO will keep the excellent work throughout.
@0LoneTech
@0LoneTech Жыл бұрын
CPython optimizes str+= if there are no other references to the left hand string, but that relies on it being able to reallocate the string data; if your other code was allocating new objects, the risk that reallocation requires a copy goes up drastically. StringIO can reduce these reallocations by keeping a margin for growth, much like list does. Your small and non-chaotic strings may have been previously allocated (e.g. interned), making the ideal case for str+= to reallocate without copying.
@cedric1731
@cedric1731 Жыл бұрын
Honestly, I am disagreeing with filter and lambda. I got so used to these functions (also due to other languages maybe) that I now find them more readable than list comprehensions, at least usually. Sometimes I still think list comprehensions are better, but nowadays it only rarely happens.
@shk_
@shk_ Жыл бұрын
Thank you so much for these videos! #pycharm
@seasong7655
@seasong7655 7 ай бұрын
I didn't know about the divmod and String io. Those are some good tips 👍👍
@erikjmurray
@erikjmurray Жыл бұрын
I always learn something from your videos! Love the content, keep doing your thing #pycharm
@niclasvonlangermann3322
@niclasvonlangermann3322 Жыл бұрын
Thank you so much! I didnt even know about the named tuple! #pycharm
@anezere
@anezere 8 ай бұрын
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
@drrros
@drrros Жыл бұрын
Thanks for the video! As always informative! I'd love to see your review for Codon compiler and it's advantages and disadvantages! #pycharm
@davidnrushton
@davidnrushton Жыл бұрын
Great tips! I love your videos, and I've learned so much. Thank you! #pycharm
@user-gd5ql2ge5r
@user-gd5ql2ge5r Жыл бұрын
Your video always inspire me where should i learn or need to firmly remember the knowledge. As always thanks !! #pycharm
@Knusperschnitte
@Knusperschnitte Жыл бұрын
Still found areas to improve. Thank you for your videos 👍 #pycharm
@bhomiktakhar8226
@bhomiktakhar8226 Жыл бұрын
Nice, easy and fast way of looking at python along with leaving with the viewer to practice and test these mistakes/habits on their own , makes me want to learn and use this language more and more. Thanks mCoding . #pycharm
@AutomatedChaos
@AutomatedChaos Жыл бұрын
Hey James, how do you feel about accepting using `or` to give a value to an attribute if it not set yet like `self.some_dependency = dependency or DefaultDependency()` in the constructor when the parameter `dependency` defaulted to `None` . Or used in a property to lazy load and cache an expensive object: `self._connection = self._connection or DatabaseConnection()`?
@VVac0
@VVac0 Жыл бұрын
My job is once again secured! Learning a lot, keep those videos coming! #pycharm
@Ballrock30
@Ballrock30 Жыл бұрын
Yes! Only 3 of 21. But honestly, some points are so advanced I never had the chance to do them wrong :D
@ALLFATHERSEN
@ALLFATHERSEN Жыл бұрын
Great video. Do you have any related content on #12 expensive attributes? I have been trying to subclass or in general make classes that I actually need to have access to secondary attributes. The problem is at times setting values to secondary attributes as self.attr1.attr2 = value does not work.
Жыл бұрын
For iterating and delete, I often just iterate the copy of it. d.items().copy(). Therefore, I dont need the second loop and the copied object will be deleted after loop anyway, so memory ussage should be the same.
@CCDHSM
@CCDHSM Жыл бұрын
Nice video. I have been coding in Python for quite some time now and still do a few of those things. Thanks for educating us! #pycharm
@mjdevlog
@mjdevlog Жыл бұрын
great content as always, mCoding, really looking into Python recently! Number 3 tips is really good! #pycharm
@ObsessiveClarity
@ObsessiveClarity 7 ай бұрын
2:17 for this particular example (though I'm not criticizing the tip), the following is even better (20% faster for n = 100000 for me -- and clearer): s = "".join(f"some string {i}" for i in range(n))
@ramon421
@ramon421 Жыл бұрын
Cool, I've done some of these in the past, will try to remember to use the better way :D #pycharm
@dragonsage6909
@dragonsage6909 Жыл бұрын
Thank you!
@loic1665
@loic1665 Жыл бұрын
Very nice!! When's part 3?? 😂
@ErdiTk
@ErdiTk Жыл бұрын
Awesome video as usual. Would love that #pycharm license btw :)
@freemarket77
@freemarket77 Жыл бұрын
Thanks for all your videos, they're super helpful #pycharm
@richardcoppin5332
@richardcoppin5332 7 ай бұрын
Even though I mainly code for Widows OS. If stopped using backslashes as a directory delimiter a long time ago. All python paths can work if you use forests-slashes and even Widows explorer handles forward-slashes so there's really no need to use backslashes in file paths in python.
@RayaneS
@RayaneS Жыл бұрын
great content to build confidence before real work experience.
@mihaitranda94
@mihaitranda94 Жыл бұрын
Thank you for yet another super useful and interesting video! #pycharm
@jimgaluska1361
@jimgaluska1361 Жыл бұрын
Another great video. Thanks! #pycharm
@philippedias4357
@philippedias4357 Жыл бұрын
Damned. I taught being proficient in my python skills but some nooby habits are still sticking. Thanks for making us realising that. #pycharm
@hardkorebhaktaofbob
@hardkorebhaktaofbob 6 ай бұрын
My man lost his voice for me! Hell yes what a guy. Great vid bro thanks a lot!
@snorklewacker
@snorklewacker 6 ай бұрын
Definitely enjoyed this, and picked up some great tips! I have to say, I’m not a fan of main() as a construct. __main__ is great, but then having it just call a main() to do everything feels unnecessary unless there’s a really good reason, and then the person importing your code has to weed it back out to avoid pulling it in. (Plus, if I’m being honest, main() feels a bit too Java-like. :) )
@Nerdimo
@Nerdimo 3 ай бұрын
6:30 I actually faced this recently with a project I’m working on. Do they both do the same thing under the hood (same byte code) or is one preferred over the other for different reasons? (In reference to using functional functions like map or filter over comprehensions).
@yaseen157
@yaseen157 Жыл бұрын
Big fan of this channel. Can't tell you the number of times I've revisited the args, kwargs, /, and * video! #pycharm
@nikocraftde
@nikocraftde Жыл бұрын
Really cool video, as always! :) #pycharm
@dkkoala1
@dkkoala1 Жыл бұрын
A "nooby" numpy habbit is also doing inp = np.array(inp) at the beginning of a function to ensure that the input is numpy for the rest of the function. This is bad because the np.array() operation actually makes a new copy of the array even if it is already a numpy array, so if there is a lot of data it will take some time. #pycharm
@python-b5
@python-b5 Жыл бұрын
This was great just like the last video! I learned a few things I'm glad I know now. #pycharm
@SunSailor
@SunSailor Жыл бұрын
Thank you, learned one or the other, especially the properties and the named tuple. #pycharm
@eudavisantos484
@eudavisantos484 Жыл бұрын
Great content, as always! I didn't quite get tip #2, should I just use lists? #pycharm
@mCoding
@mCoding Жыл бұрын
The point of the tip is: it depends! If all you want to do is take a max, then a list may be faster than a numpy array. But if you are doing a bunch of math operations, then using a numpy array is likely faster. But if those operations are custom and can't be built out of efficient numpy primitives, then using a list may be faster! Ascending beyond noob status means recognizing that there isn't just one answer!
@harperfrost9137
@harperfrost9137 Жыл бұрын
Always coming in clutch with these tips #pycharm
@rilakkuma-ali5909
@rilakkuma-ali5909 Жыл бұрын
Thanks for another great video! #pycharm
@dantezco
@dantezco Жыл бұрын
I'm both glad to have learned a few new things and realized that many of them I already knew :-) always good to see a measure of progress. #pycharm
@doctortroels
@doctortroels Жыл бұрын
#5 is slightly misleading, since it depends on the python implementation. The statement is true for PyPy, but CPython cleverly uses a reference count of one to make the string mutable. The proposed fix has the exact same performance in CPython (replace 100 with 10000000 to get a proper measurement).
@grawss
@grawss Жыл бұрын
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.
@danielulvr500
@danielulvr500 Жыл бұрын
Nice video! Always informative and on point. :) #pycharm
@chrysos
@chrysos Жыл бұрын
been waiting for this kind of video #pycharm
@gradientcube
@gradientcube Жыл бұрын
I appreciate these videos. May as well try my chances with #pycharm
@jpulliam83
@jpulliam83 Жыл бұрын
Thank you for the tips. #pycharm
@gvarph7212
@gvarph7212 Жыл бұрын
I have a question about #7. If I have some global constants, is it ok to use them directly in functions, or should I pass them through few layers of functions from main?
@liamwatts7105
@liamwatts7105 Жыл бұрын
I think constants are fine, denote them by writing in UPPER_CASE_SNAKE_CASE
@mCoding
@mCoding Жыл бұрын
Great question! ALL these nooby habits are okay and they all have situations where they are, in fact, quite reasonable things to do. Just as you suspected, using a global constant is a perfectly reasonable thing to do.
@pabloreydaniel
@pabloreydaniel Жыл бұрын
very helpful!!!! thanks keep up the good work. #pycharm
@trag1czny
@trag1czny Жыл бұрын
Great video! 🤩
@jagannathpadhy1821
@jagannathpadhy1821 Жыл бұрын
Damn, I thought I was being proficient in my python skills but some nooby habits are still sticking. Thanks for making us realising that. #pycharm
@murphygreen8484
@murphygreen8484 Жыл бұрын
#pycharm "... That tech job you somehow got" oof, felt that! Great videos though, these videos never fail to help!
@bereck7735
@bereck7735 Жыл бұрын
Very fun video and very informative, also nice puns in the video. #pycharm
@Jim-fs4jd
@Jim-fs4jd Жыл бұрын
Thanks for the video! #pycharm
@dinofish3262
@dinofish3262 Жыл бұрын
Been waiting for a Mooney habits vid for a while #pycharm
@Finkelfunk
@Finkelfunk Жыл бұрын
Small annotation to 10: The reason you do this is that most processors use a divmod that is built in already. That means the processor will most likely perform the operation twice only to discard the mod in the first go around and the result in the second.
@bee_irl
@bee_irl Жыл бұрын
yes definitely microoptimize your assembly code in python, the performance increase will be tremendous
@pallytank09
@pallytank09 Жыл бұрын
Thanks for another great video. #pycharm
@Zifox20
@Zifox20 Жыл бұрын
@viniciushulks09
@viniciushulks09 Жыл бұрын
Awesome video, helped a lot! #pycharm
@suncake_xd
@suncake_xd 7 ай бұрын
I have a question. Parsing data structure such as dict from a string was mentioned as a bad thing, but I found it to be the best ways to store nested dictionaries parsed with json in redis. Are there alternative ways? hset and hmset dont work well with nesting, and return all values as strings, which is not the case whien using json dumps and loads
@iyadahmed3773
@iyadahmed3773 Жыл бұрын
Amazing video as always!, #pycharm
@slash_me
@slash_me Жыл бұрын
Is it more efficient to create a set of keys to delete and looping a second time or to create a copy of the dict's keys with list(d.keys()) and iterating over that? Because that's what I usually do. #PyCharm
@turtlx
@turtlx Жыл бұрын
Thanks for the tips! #pycharm
@Naigo1
@Naigo1 Жыл бұрын
Love your videos. Thanks for making me less nooby #pycharm
@aminysh6877
@aminysh6877 Жыл бұрын
i really like your contents , they are organized , simple , straight to the point and so helpful ... #pycharm
@user-xv6cj1gl8w
@user-xv6cj1gl8w Жыл бұрын
Good luck in your path of learning and a #pycharm license would be nice, yes
@oscartheodorius1122
@oscartheodorius1122 Жыл бұрын
Your videos are always helpful, thank you. And I would like to take one of the licenses #pycharm
@UnkindledOne1
@UnkindledOne1 Жыл бұрын
Great video as always!! #pycharm
@TheJocadasa
@TheJocadasa Жыл бұрын
These kinds of videos are very fun and digestible. #pycharm
@davidkolesanov9328
@davidkolesanov9328 Жыл бұрын
7:03 But what if I want to use the "+" operator? Then, wouldn't I HAVE to implement the "add" dunder method, instead of just a regular method?
@danitegue
@danitegue Жыл бұрын
#pycharm Great! A bit fast, I had to stop the video to understand a few parts but in general very good tips!
@nagarajurepala
@nagarajurepala Жыл бұрын
Thanks for the #pycharm giveaway!
@ThePowerRanger
@ThePowerRanger Жыл бұрын
Didn't knew about pathlib, this video is going on my playlist #pycharm.
Unlocking your CPU cores in Python (multiprocessing)
12:16
mCoding
Рет қаралды 291 М.
Python Generators
15:32
mCoding
Рет қаралды 128 М.
New Gadgets! Bycycle 4.0 🚲 #shorts
00:14
BongBee Family
Рет қаралды 11 МЛН
1❤️
00:20
すしらーめん《りく》
Рет қаралды 33 МЛН
15 Python Libraries You Should Know About
14:54
ArjanCodes
Рет қаралды 357 М.
5 Good Python Habits
17:35
Indently
Рет қаралды 344 М.
Python JSON Mastery: From Strings to Services
13:36
The Code Guy
Рет қаралды 722
5 Signs of an Inexperienced Self-Taught Developer (and how to fix)
8:40
super/MRO, Python's most misunderstood feature.
21:07
mCoding
Рет қаралды 211 М.
Metaclasses in Python
15:45
mCoding
Рет қаралды 148 М.
8 things in Python you didn't realize are descriptors
14:21
Every Python dev falls for this (name mangling)
14:11
mCoding
Рет қаралды 135 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 718 М.
Rust Functions Are Weird (But Be Glad)
19:52
Logan Smith
Рет қаралды 125 М.
Mi primera placa con dios
0:12
Eyal mewing
Рет қаралды 468 М.
wyłącznik
0:50
Panele Fotowoltaiczne
Рет қаралды 23 МЛН
Не обзор DJI Osmo Pocket 3 Creator Combo
1:00
superfirsthero
Рет қаралды 1,2 МЛН
Карточка Зарядка 📱 ( @ArshSoni )
0:23
EpicShortsRussia
Рет қаралды 417 М.
как спасти усилитель?
0:35
KS Customs
Рет қаралды 520 М.