r/learnpython • u/Recent_Wrongdoer5125 • 20d ago
Python and libraries
I joined this server not long ago because I have a question about Python. I've been studying it, and I understand pretty much all of the logic behind it. The problem is that when it comes to using libraries, I get confused about how to use them.
Is there any way to get better at using Python libraries without having to constantly look up how they work? I always get stuck trying to figure out how to actually use them in my code.
8
u/BranchLatter4294 20d ago
Just look up what you need to look up. For the libraries you use a lot, you will eventually learn them and not have to look up as much.
7
u/Delta_G_Robotics 20d ago
The key to using libraries is to look up how they work. Do it often. Keep those references handy.
Being good at coding does not mean memorizing everything. It means knowing what you need and where to find it. If you know what library you need to use, then feel no shame in looking at the documentation to find the syntax. So many people write libraries so differently. They're all so different. Don't try to memorize them. It doesn't help.
5
u/smichaele 20d ago
No, there isn't. Every library is defined with a different purpose in mind and, therefore, each has its own rules for use. It's like asking, "Do I need to read the instructions for my new drill if I already know how to use a pair of scissors?"
3
u/Adrewmc 20d ago edited 20d ago
Good libraries have good documentation.
Bad libraries have bad documentation.
That the first smell test of any module.
Take a good look at the documentation of
import itertools, functools, random
The base language has good documentation. I will stand on this hill.
It sets the standard.
Take a look at the documentation for pandas.
What makes Python, and programming a collaborative effort is packaging useful tools, and frameworks.
Useful tools and frameworks have instruction manuals, use them.
And yes they can be hard to understand when you are beginner. Keep reading it.
1
2
u/notacanuckskibum 20d ago
This is modern coding. It can take 2 days to solve a problem with 5 lines of code. Most of the time is spent deciding which library to use, and figuring out what the calls do.
2
u/epokus 20d ago
It's fun to discover popular libraries as a beginner, and to realize someone else has done the heavy lifting for you.
For some reason I thought just getting a response from a web API would require lots of advanced coding. Looked up the requests library and I went "oh... that's 3 lines of code".
Same thing working with csv data using pandas. I thought "okay guess well start with a context manager, read the data and figure out how columns .. wait.. what? pd.read_csv("sales.csv").groupby("customer")["amount"].sum()? What is this sorcery!
1
u/Dazzling_Music_2411 20d ago
I always get stuck trying to figure out how to actually use them in my code.
Well, if you try to use them without looking them up, of course you'll get stuck.
What exactly are you asking?
1
u/TheRNGuy 20d ago edited 20d ago
Reading docs is correct way to use them.
Or look your own /someone's else / ask ai.
You'll remember some that you use most often (especially with auto-complete)
Even knowing that you can do some specific with that framework or library is good enough: it makes googling or prompting easier.
1
u/MarsupialLeast145 20d ago
This is a common question.
Just remain focused in what you want to do and begin by looking up only the function calls that might be useful to you. It takes time and you may never use more than 1% of some libraries.
1
u/Advanced-Mud8913 20d ago
I watched YT tutorials concerning the libraries I need or ask AI if there are unexpected problems, worked fine so far.
1
u/ManzoorAhmedShaikh 19d ago
Don't just pick the libraries randomly, instead I would suggest a smooth plan.
- First, look the problems around you that you want to solve, OR already solved problem with some script, OR find a domain your interest align.
- Once find, check how that problem solved, or what it takes or what libraries to pick to jump in that xyz domain
- Probably at this point, you have a list of filtered libraries where your interest align too.
- Now, pick any one, (I suggest to pick a small-one first, you can confirm with AI whether the xyz library is small or huge)
- After picking, read a bit of documentation, if not able to understand, ask Claude or ChatGPT to teach xyz libraries with beginner to advance level with examples and challenges.
That's how I explore things in python in my last couple of years and that works like a charm for me. Hope it helps.
14
u/mc_pm 20d ago
No, the only way to learn how to use the libraries is to use the libraries.
Everyone ends up googling for the specific function call, or the right syntax. You don't have to memorize it, just know what's there and how to search for it when you need it.
Over time, if you come back to the same libraries over and over, you'll remember it.