r/learnpython • u/coreyschafer • Apr 22 '19
5 Common Python Mistakes and How to Fix Them
I make Python videos on YouTube and get a lot of questions every day. I found these 5 mistakes to be common problems, especially for those who are learning Python. Hope some of you find this helpful. Video here:
Cheers
10
u/dukesilver58 Apr 22 '19
Cory you set me on a path! Thank you for your videos. You and engineerman changed my life
2
u/coreyschafer Apr 24 '19
Yeah, EngineerMan is great. I’m going to put out a video in the next couple of months on my other favorite YouTubers and he’s definitely going to make the list.
4
u/cmcgarveyjr Apr 22 '19 edited Apr 22 '19
lol, I watched this earlier today on my lunch break. Great video!!! I recommend your channel all the time.
EDIT: Because I dont know how many times I will ever get to comment and you probably read it. I love how your tutorials have real world examples! Like your recent web scraping video for requests-html. If there is one thing that really makes it hard to follow, its tutorials that teach around a vague example that has no real world use/value.
2
u/coreyschafer Apr 24 '19
Ah thanks. I’ll definitely try to include as many real-world examples as I can in future videos.
25
3
u/Ron_Swanson_Jr Apr 22 '19
Bookmarking this for later. I don't know how much time /u/coreyshafer puts into each video. I'd really be interested to find out, but even more interested to find out how much time the Corey's videos have saved people that are just learning python. I remember banging my face on my keyboard to some of the subjects his videos clearly and concisely teach. Thank you for your contribution!
8
u/coreyschafer Apr 22 '19
The time it takes really depends on the video. I have some data science videos I’m working on now that are taking a long time to put together (over a month or so). Data Science was never my strongest area, so I’m going back and learning a lot myself to make sure I’m following best practices and latest standards. It also takes a long time simply finding data I think will be interesting for people to follow along. I find that charting random numbers tends to get people to fall asleep, so I want some real data that is more relatable. So videos like that can take a long time to put together.
If I know the topic well already then I can put a video together in a couple days. Usually write the script and examples one day and then record/edit/release the next. All-in-all I tend to put out about a video a week, but there have definitely been gaps where I don’t release for a few weeks at a time.
10
u/pat_the_brat Unchaining Django Apr 22 '19
Thanks, but I'd much rather see a 5 bullet list than watch a 30 minute video...
85
u/coreyschafer Apr 22 '19
There is a bulleted list in the description. Here is what is discussed in the video:
Indentation and Spaces - 0:45
Naming Conflicts - 4:12
Mutable Default Args - 10:05
Exhausting Iterators - 16:35
Importing with * - 22:13
19
u/MrZe1598 Apr 22 '19
And for future reference, Corey is always on point with adding the timestamps on the video descriptions.
6
u/00001990 Apr 22 '19
I would say it’s clearly some of the issues I had when I started learning. The worst part is figuring out why something isn’t working properly when you don’t know about this. Great video!
1
u/wildbk33 Apr 23 '19
What's wrong with importing *?
7
u/coreyschafer Apr 23 '19
I mention it in the video, but there are a couple reasons it can come back to bite you. First, it makes your code hard to debug. If you’re using a function that was imported with the wildcard then there’s no clear way to know that’s where it came from. So tracking down bugs can be a pain. Second, and probably less common, it can overwrite other function with the same name. If you import using * and there is a function with the same name then it will be overwritten.
1
u/wildbk33 Apr 23 '19
How often does that really happen though where someone with the knowledge to write a function duplicates the name? I would personally find it a pain in the ass to import only what I need instead of Star
1
u/coreyschafer Apr 23 '19
Aside from possibly overwriting function names, I believe the biggest issue lies in debugging and the ability to track down mistakes. If you’re using a lot of wildcard imports, once your project grows to any considerable size it is going to be a nightmare to see where all of the functions and constants are being imported from. If you don’t want to type out the entire module I highly recommend simply using a abbreviated version of the module name like many people do with numpy and pandas... import numpy as np
1
Apr 23 '19
It's not that someone imports their own functions. It typically happens when importing from other modules. (The example given in the video included such popular modules as Flask, html, and glob.)
If you were going to import star, just import the whole module and use the module namespace.
-17
u/socal_nerdtastic Apr 22 '19
As an experienced teacher on this subreddit, I'd say those are very uncommon issues. It's been years since I've seen a wildcard import cause a problem (of course we still constantly remind people not to use them).
Please consider this an invite to hang out here and help newbs. You can write it off as "research" and plug your channel.
18
u/coreyschafer Apr 22 '19
That’s probably the one I see least often, but I’ve had enough questions about it to write it in my notes. The most common one I see from that list is probably misnaming files. Especially when people are learning, it’s very tempting to learn about datetime and name the file datetime.py.
And yeah, I’d like to comment more in here. I poke in front time to time, but I don’t comment much. I stay pretty busy with email questions and comments, but would like to help out on other platforms. Just need to slot out some time.
-2
u/socal_nerdtastic Apr 22 '19
Fair enough. We plug your channel plenty around here. You can tell from my downvotes how unpopular anyone is that would dare question you lol.
If you need inspiration for another one you could literally just pull the list from our FAQs.
8
u/coreyschafer Apr 22 '19
Oh no, I think you made a fair point about wildcard imports. I do appreciate constructive criticism or recommendations, especially from other teachers. I'll definitely check out the FAQ. Thanks
3
u/Binary101010 Apr 22 '19
The wildcard import one feels fairly unusual to me, granted.
But naming conflicts and exhausting iterators? I see those in here on a daily or almost-daily basis.
-4
7
u/Spookiel Apr 22 '19
Your videos are really great Corey! I find these “compilation” type of videos really helpful as it only requires one click onto a single video to get a variety of things which I think makes the video more engaging to watch.
7
Apr 23 '19
I was just thinking yesterday that I should post some kind of recommendation on here for u/coreyschafer videos. I'm not surprised to see he's already here. As I've been learning Python this past month, I've found his videos to be way above the rest.
5
u/he1mdall Apr 22 '19
This was a very nice vid!
I've been trying to learn python for the last weeks with very little programming background, and having started a complex (for me) project thats grown way bigger than I anticipated I ran into a problem while trying to iterate through an object twice. Took me a long time to figure that one out, felt like I was slowly going insane...
4
4
u/TarnishedTeal Apr 22 '19
This is super engaging. I have adhd and it’s really difficult to watch videos. But I watched the whole thing. Subscribed.
2
Apr 23 '19
Everything I know of Python is because of you and your helpful videos. Nice to see you here.
2
1
1
u/Jrusk2007 Apr 23 '19
This is so funny. I was just watching one of your videos ten minutes ago... Before I got on Reddit...
1
1
u/losingprinciple Apr 23 '19
Thanks for your videos.
I'm super new and learning on my own for the most part and it's such a struggle haha. I was watching this video and it helped out a lot.
1
u/sgthoppy sgtlaggy Apr 23 '19
Great video, but I caught something in your add_employee example. Around 13:35 where you say you could also use if not emp_list, that would have a side-effect that may be difficult to figure out. When an empty list is passed in, you will override it with the new list, and the one passed in wouldn't have anything appended to it.
1
u/n8state Apr 23 '19
How accurate are the auto-generated captions on this series? I’d be interested in watching but I couldn’t confirm I’m getting all of the information.
1
1
1
0
Apr 22 '19
[deleted]
7
1
u/motor11 Apr 23 '19
I've got to look into that video (I feel the same about virtual environments).
Thanks for the videos u/coreyschafer
147
u/totororos Apr 22 '19
Yeah, like we don't know who you are, Corey ;) Thanks a lot for your videos. They're ridiculously helpful.