Top products from r/pythontips

We found 8 product mentions on r/pythontips. We ranked the 6 resulting products by number of redditors who mentioned them. Here are the top 20.

Next page

Top comments that mention products on r/pythontips:

u/DBA_HAH · 3 pointsr/pythontips

I mean... almost everything you touch uses classes.

Let's take reddit. How would you handle users without a class? Retrieve the info from the database and push it into a dict? Now what if you want to delete the user? Create a separate function called `delete_user` that accepts a dict?

What if you want to enable validation on a created user (valid email, username not taken, etc)? Are you always going to do that on the database layer? Or are you going to have a separate function called `validate_user` that accepts a dict?

Etc, etc. You end up with a clusterfuck of functions that all accept any dict.

The best example of using classes probably comes from inheritance. Let's say we also want to include admins in reddit which are a subclass of users. Maybe admins are considered employees so they get extra fields such as mailing address, real name, telephone number, etc but also get to function as users on reddit. Without classes you would create a different dict structure with 90% of the code being duplicated whereas with classes, an Admin would inherit everything from dict and you would only add what's specific for Admins.

Now lets say you need to make a change so that any User can have a longer username or users can now have a friend's list. Without classes, you now need to change the code in two places (User and Admin dicts) whereas with classes we only have to do it once since we use inheritance. Now imagine if there were 12 different kinds of users. With classes you only ever have to change the code in one place.

The reason why we use classes is to organize the code. It's much easier to find out how a program creates, validates, deletes a user when it's all stored in a User class than trying to find out which functions to use, hoping the function names are clear, etc.

Beyond this, using OOP unlocks Design Patterns which have decades of research and real-world use behind them as proficient ways to design programs.

If you're just hacking around with scripts and the like then you probably don't need a class. But if you're designing an application that's going to have many recurring objects (users, cars, comments, Tweets, emails, line items, products, etc) then you realistically need classes.

TL;DR - Make your code DRY - don't repeat yourself. If you find yourself repeating yourself, you need to investigate why and often times there's an OOP principal or design pattern to fix it.

u/chra94 · 19 pointsr/pythontips

Automate the Boring Stuff taught me the basics and I recommend it highly. It's free.

If you encounter an error spend about an hour trying to solve it before asking for help. If you get an error with an error message from running the program you copy and paste the error message into a search engine and look for answers there. If the program behaves differently than you expect it too without giving you an error message you have probably made a mistake in your instructions to the program and these can be hard to find.

r/learnpython is great when you can't solve your problem(s), they're helpful as long as you say what you have tried, upload your code to and say what you want the program to do.

also when giving variables names please give them describing names. look at this example:

name = "chra94"

n = 6

name_length = 6

clearly name_length describes itself better than just n. Many beginners me included make the mistake of naming variables poorly which makes the code harder to read. good variables makes reading the code easier.

Be prepared to read documentations for both python but also tools (they're called modules or libraries) written in python for python. One day you might want to make a program that modifies or creates spreadsheets. There are libraries for that and even if you just watch a tutorial on how to use it it's easier to be able to search and read the documentation for the module than finding a tutorial specific for that one little thing you want to do that the other tutorial didn't cover.

Following the Automate the Boring Stuff book you will be able to make a rock, paper, scissors-game, making a number guessing game and such. Should you want more excercises you could look at codingbat over here at CodingBat for that.

Some day you might want to do a project. A program that's useful. Maybe it'll download the ten best wallpapers from r/wallpapers each day. Maybe you'll make a chatbot Slack or Discord or IRC. Anwyay. After having made a couple of programs that can be used over and over again by someone else than me I have realized that I have to plan much, much more ahead. My programs got messy, difficult to read, difficult to change and honestly I've lost control over them. I wish I had read Code Complete earlier. It praises planning your program thoroughly. According to some stats in the book mistakes uncovered after planning are between five to ten times more costly to fix than if they were discovered while the requirements for the program were figured out. (Theses stats are for small companies. Bigger companies can be as much as 100 times more expensive to fix.) TL;DR: Time spent planning is between three to ten times better spent than fixing stuff because you didn't bother to plan enough.

*TL;DR:** Do Automate the Boring Stuff untill you want to make stuff on your own and read chapter three of Code Complete.

Best of luck buddy and remember: Plan your projects ahead.

u/gatewaynode · 14 pointsr/pythontips

A nice learn as you build web project is :

If Python is just a new language this is a really good book for hitting that next level:

Here's a site worth reading most updates:

And definitely subscribe to r/learnpython, it's a friendly place for all levels of Pythonistas.

u/zombieman101 · 3 pointsr/pythontips

I haven't used this book myself, but I've heard great things about it, this might be a good route to go:

u/GDK_ATL · 7 pointsr/pythontips

You might want to read this first.