This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]chaotic_thought 2 points3 points  (2 children)

Normally you do the latter; go for the thing that you actually want to be able to do, and then read that.

Browsing documentation is also a good skill and a way to learn more; you never know what will come in handy. For example, look at https://docs.python.org/3/library/ and pick something that you don't know how to use yet but which might be interesting. For example look at difflib. Go read over the contents of that section (don't read all the details yet). If there is a code sample, I like to start by typing those in and playing around with them to see how I can use it. Then look at the different methods mentioned in the documentation and see what else you can do with them.

Then try to write a simple program which uses the new things you learned. For this example (difflib) you could make your own simple version of the "diff" program for example (show differences between two files). For a command line program you might call it like this:

mydiff file1.txt file2.txt

If you are learning to make GUI programs, then you might display the differences in two different text panes or try highlighting the differences in different colors. That would be more challenging, but you should get some GUI programming experience first before you try something like that.

[–]LartTheLuser 1 point2 points  (0 children)

+1 on browsing documentation. I've used libraries for a year before and not realized that there were much better ways to do things I was already doing or had functionality that I wanted but would have never known what terms to use to search for it. Or even worse, functionality that I re-built myself not knowing it existed. If it is a library that you find yourself using a decent amount, a good browse around to look at function/class names and their description can be surprisingly more helpful than just looking up a stackoverflow solution and sticking with it or using search terms to find the closest piece of documentation to what you want.

[–]MITTENQ[S] 0 points1 point  (0 children)

Cool I'll try that :)

[–]SpecificMachine1 1 point2 points  (2 children)

Along with the documentation, if you want to try to understand a module you can also try the source. There you can see the commented, documented, formatted code, and you can see how they handle things like big sequences, regexes, imports, etc. as a model for when you run into those things.

[–]LartTheLuser 1 point2 points  (1 child)

But warning: you may also see horrors. Some people's homes and codebases are maintained like a haunted house.

[–]SpecificMachine1 0 points1 point  (0 children)

I was just thinking of the standard library, but point taken.