Knowing this can save you HOURS of debugging! (5 Python Pitfalls)

Knowing this can save you HOURS of debugging! (5 Python Pitfalls)

Patrick Loeber

2 года назад

46,740 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@ThankYouESM
@ThankYouESM - 29.07.2023 04:45

"is" != "=="

Ответить
@ThankYouESM
@ThankYouESM - 29.07.2023 04:44

In StackOverflow, had found over 100 of such Python Pitfalls listed which a friend suggested I learn before writing my own code.

Ответить
@viddeshk8020
@viddeshk8020 - 21.07.2023 09:55

😂 seeing this in 2023 😅

Ответить
@JOHNSMITH-ve3rq
@JOHNSMITH-ve3rq - 13.04.2023 16:17

Appalled at this language. Though I also love it 😂

Ответить
@JOHNSMITH-ve3rq
@JOHNSMITH-ve3rq - 13.04.2023 14:48

My gosh that is such stupid behaviour by python. Ridiculous!!!

Ответить
@castlecodersltd
@castlecodersltd - 25.11.2022 13:26

Really helpful, thank you ☺

Ответить
@personx9450
@personx9450 - 21.10.2022 14:27

Helpful 👏

Ответить
@raminmousivand4257
@raminmousivand4257 - 17.08.2022 02:43

Fantastic tutorials. Please keep going buddy 👌🙏

Ответить
@raiyan22
@raiyan22 - 27.04.2022 20:03

learned sth new today !! Thanks

Ответить
@caiyu538
@caiyu538 - 26.01.2022 18:47

great lectures. Really tricky in python. Thank you so much.

Ответить
@jesusmtz29
@jesusmtz29 - 04.01.2022 19:19

i wonder who thought this was a good idea lol maybe ther'es a good reason

Ответить
@rendomstranger8698
@rendomstranger8698 - 24.11.2021 02:53

I wish I had seen this video 2 weeks ago. I spent about an hour debugging a program because of the whole 1 item tuple situation. Took me a while to figure out that it was the tuple that was causing problems and even longer before I discovered that the function it was a part of was returning a string instead of a tuple. Thinking about it further, I should probably be checking for type instead of length in my program and just leave the string as a string.

Ответить
@davidbeauchesne7399
@davidbeauchesne7399 - 22.11.2021 21:07

thanks! good tips for the new python user.

Ответить
@boem231
@boem231 - 12.11.2021 17:09

This is exactly why I hate python

Ответить
@nexusclarum8000
@nexusclarum8000 - 05.11.2021 19:19

That's actually probably some residual ideology coming from C/C++. In C/C++ if you have a large string literal you want to break up on multiple lines you can make each line in its own quotation and it'll just treat it as a single string literal.

Ответить
@johnjoyce
@johnjoyce - 05.11.2021 16:33

Finally, most of these can be avoided by adopting the emerging more explicitly typed coding style using the typing module extensively with mypy and using explicit constructors to avoid ambiguity even when it is visual ambiguity. The fast and loose nature of many scripting languages has begun to wear thin and we are seeing the emergence of explicit typing style as scalable and reducing a class of runtime errors by preventing them. TypeScript is an example of this along with Hack and others.

Ответить
@johnjoyce
@johnjoyce - 05.11.2021 16:28

The single element tuple gotcha is half the reason I always always add the comma after the last element of every collection. It always expresses correctly and if aligned with each collection member or element on separate lines, then it is easier to reorder the collection in code and see deltas in diffs and help git better understand merges as it is so line oriented.

Ответить
@johnjoyce
@johnjoyce - 05.11.2021 16:18

Yeah. That string concatenation “feature” is a misfeature in most contexts. Should be removed along with unparenthesized tuple because similarly hard to spot comma can cause syntactically valid but crazy bugs.

Ответить
@evlezzz
@evlezzz - 05.11.2021 05:12

Explanation for conditional expression is wrong. It has nothing to do with consistency. It's caused by operations priority within expression. Since priority for comma operator is lower than for conditional operator, "(a, b) if x else c, d" is actually parsed as "((a, b) if x else c), d".

Ответить
@chaosopher23
@chaosopher23 - 04.11.2021 22:47

Those are not bugs, they are features.

Ответить
@paulabraham2550
@paulabraham2550 - 02.11.2021 00:09

Good grief. The more I learn about python ...

Ответить
@maman14141414
@maman14141414 - 01.11.2021 22:37

for the tuple example there is actualy a trick you can just write ("one",) wth a trailing comma to have the desired behavior

Ответить
@MrCmon113
@MrCmon113 - 29.10.2021 00:07

I wrote a conditional that always returns true in my bachelor thesis. Hundreds of hours of GPU time wasted, because I only found the mistake after weeks.

Ответить
@Tennisbull-match-statistics
@Tennisbull-match-statistics - 20.10.2021 04:57

What other functions are in place operations?

Ответить
@JohnZakaria
@JohnZakaria - 16.10.2021 11:51

I have done all of these mistakes as I started doing python.
Accuracy 100%

Ответить
@coniferviveur3788
@coniferviveur3788 - 14.10.2021 16:12

Thanks for that. Your explanations are very clear and your use of examples is excellent.

Ответить
@majkelpl8611
@majkelpl8611 - 10.10.2021 22:52

I preferred your face rather than memes. Video as always, great.

Ответить
@saumodipdas3624
@saumodipdas3624 - 10.10.2021 06:00

Really good video. Though I used to get correctly 4 of these but never paid attention to the errors otherwise. So thanks for the info. Keep it up 😀😀😀

Ответить
@Yotanido
@Yotanido - 10.10.2021 04:09

I knew about all of these and could correctly predict what each shown program was going to do.

That said, append being an in-place operation and returning None has annoyed me a lot when I first started to use python. Coming from Haskell, mutating lists like that was just... weird.

I still think it should return the list, even if it does change it in place, since it would allow you to chain calls.

Ответить
@akshaysrivathsa227
@akshaysrivathsa227 - 13.09.2021 16:00

Can u pls make a pytorch project like the snake game

Ответить
@saurrav3801
@saurrav3801 - 07.09.2021 17:48

🔥🔥🔥🔥Great job bro

Ответить
@imdadood5705
@imdadood5705 - 06.09.2021 11:35

Once you learn the basics of python. This solidified the understanding further. Thank you for this!

Ответить
@ktrivikram1311
@ktrivikram1311 - 06.09.2021 06:12

Your project name is wtf python 🤣

Ответить
@AR-fh2uh
@AR-fh2uh - 05.09.2021 20:40

I was there today.
Working on a client server model.
It wouldn't work for love or money.
Turns out, after a complete refactor the client and server were using a different message header length. I was setting specifically in thier init statements.

Ответить
@michalbotor
@michalbotor - 05.09.2021 20:33

i have never expected to burst into laughter once someone had explained to me where the flaw in the code lies...


i'm talking about you: `x, y = (1, 0) if condition else None, None`

Ответить
@pacersgo
@pacersgo - 05.09.2021 19:56

It is a very good video. I have written at least three of those bugs, that did take me quite some time to figure out what happened..

Ответить
@laugedyret
@laugedyret - 05.09.2021 19:13

I love it!

Ответить
@siranjeevis1176
@siranjeevis1176 - 05.09.2021 18:49

Post video more videos like this

Ответить
@dominikwodarczyk6714
@dominikwodarczyk6714 - 05.09.2021 18:05

Thanks <3

Ответить
@nort1793
@nort1793 - 05.09.2021 17:43

I am sixth!!!

Ответить
@__________________________6910
@__________________________6910 - 05.09.2021 17:34

Thanks, "Happy Teachers Day" from INDIA

Ответить
@Jxrdy
@Jxrdy - 05.09.2021 16:57

wtf python

Ответить
@vivekan97
@vivekan97 - 05.09.2021 16:16

Very informative 👍👍👍 Looking for more

Ответить
@victorpinasarnault9135
@victorpinasarnault9135 - 05.09.2021 16:11

Thanks a lot

Ответить