r/learnpython • • Feb 20 '21

What are you having difficulty learning or are currently struggling to learn?

I'm curious what the community here has difficulty with when it comes to learning Python. Partly because I want to see if the more experienced community here (or myself) can help point you into the right direction. . . but also because I'm trying to come up with video tutorial ideas for future content and would love to hear from Python learners what would be most useful to dedicate our time on.

I'm looking forward to hearing what you guys have to say!

417 Upvotes

324 comments sorted by

View all comments

Show parent comments

3

u/NightSkyth Feb 20 '21

And what's the point? Is it something like you don't want to modify directly your function by being too intrusive for instance?

6

u/Moikle Feb 21 '21

possibly something like a certain behaviour that you want to happen before and/or after multiple functions, and you don't want to have to rewrite it for each.

They are great for debugging. Maybe you want something to time how long functions take without actually modifying the function itself.

Really though, the trick is to learn how they work, and a couple of tricks you can do with them, and suddenly you will start coming up with your own uses for them.

3

u/groovitude Feb 21 '21

Is it something like you don't want to modify directly your function by being too intrusive for instance?

That's a good example of a use case. I think logging is a pretty ideal example of where you'd want to use a decorator. It enables you to have a single source of truth for how you do your logging -- if you decide to change something about how you log, you only have to change it in one place and not search all over for every example. It also keeps the logic for doing the logging out of the rest of the logic, keeping your functions clear and focused.

3

u/totemcatcher Feb 21 '21

One simple use case is to allow a function to support a variation of arguments. A function which takes an integer can be decorated to take a list. The decorator definition breaks the list into integers and repeatedly calls the decorated function with each index of the list.

1

u/NightSkyth Feb 21 '21

Oh, good idea. It could be very useful actually.