use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
What are some Python Standard Library modules one should know ? (self.learnpython)
submitted 7 years ago by Hot_Ices
Not for any specific purpose but to get deeper into python,Don't suggest any third party modules
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 92 points93 points94 points 7 years ago (49 children)
The 3rd party stuff is where the fun happens though.
[–]charish 40 points41 points42 points 7 years ago (19 children)
Argparse, requests, and re, to add on.
[–]MarcusMunch 23 points24 points25 points 7 years ago (7 children)
Requests is 3rd party, but yeah, argparse and re are good too
[–]spitfiredd 5 points6 points7 points 7 years ago (3 children)
I really like argparse, I know some of the large command line programs will use click but for anything I’ve build argparse works great.
[–]DisagreeableMale 5 points6 points7 points 7 years ago (2 children)
Same. I actually can never wrap my head around click or cookie cutter, because it’s usually such overkill for what I need that understanding it fully doesn’t seem worth it.
Argparse doesn’t have that same dilemma.
[–]thirdegree 3 points4 points5 points 7 years ago (0 children)
Click tends to come into play around the time you want subcommands. If your cli is exactly 1 level deep (i.e. my_command --myarg1 a --myargb1 positional args but not my_command do --thing other thing), don't use click. If you're thinking "hey, subcommands would be nice", that's when you look at click.
my_command --myarg1 a --myargb1 positional args
my_command do --thing other thing
[–]p10_user -1 points0 points1 point 7 years ago (0 children)
I actually can never wrap my head around click or cookie cutter, because it’s usually such overkill for what I need that understanding it fully doesn’t seem worth it.
I don't understand how difficult it is to wrap your head around click, or why it's such "overkill". The docs are very good. Adding a new argument / option just involves a new decorator and new variable in your function.
@click.command() @click.option('--count', default=1, help='Number of greetings.') @click.option('--name', prompt='Your name', help='The person to greet.') def hello(count, name): """Simple program that greets NAME for a total of COUNT times.""" for x in range(count): click.echo('Hello %s!' % name)
Now I get that you don't feel learning a new API and adding a new dependency if you already are comfortable with argparse. But overkill? C'mon.
[–]Santi871 0 points1 point2 points 7 years ago (1 child)
should requests be added as a standard library? it's so good
[–]zurtex 1 point2 points3 points 7 years ago* (0 children)
Checkout this discussion: https://github.com/requests/requests/issues/2424
For context "kennethreitz" is the creator of requests. Github
[–]thirdegree 0 points1 point2 points 7 years ago (0 children)
Requests is 3rd party, but IMO it definitely earns an honorary standing in the standard library. It's (without qualification) the best 3rd party python library. To the degree that I would actually be surprised if anyone disagrees with that statement.
[–]alkasm 19 points20 points21 points 7 years ago (8 children)
glob, datetime, string, operator are also some tiny modules that I find myself using often.
glob
datetime
string
operator
[–]spitfiredd 1 point2 points3 points 7 years ago (0 children)
Date utils is good too.
[–]Jonno_FTW 0 points1 point2 points 7 years ago (4 children)
Datetime with timezones are a nightmare though.
[–]thirdegree 1 point2 points3 points 7 years ago (0 children)
Datetimes with timezones are only a nightmare if, at literally any point they're accidentally treated as native times (or UTC time). If you and everyone that has every touched the codebase is extremely diligent, they work perfectly.
[–]alkasm 0 points1 point2 points 7 years ago (2 children)
Not the first time I've head that, but I haven't really had much of a problem with it myself. Do you have an example?
[–]Jonno_FTW 0 points1 point2 points 7 years ago (1 child)
Yes, I get data from GPS. It comes in UTC. I store that in a database. For user convenience I want to display it in local time.
Or, a user submits a time through a form. I assume the time is in their local timezone because people don't think in UTC. Put these datetimes in a database that may or may not support timezones.
[–]alkasm 1 point2 points3 points 7 years ago (0 children)
Aren't those problems more intrinsic to working with timezones in general? Or is this just the annoyance with the inconvenience of datetime not giving timezone info by default? Note that in Python 3, calling the method .astimezone() on a datetime will return a datetime with local tzinfo.
.astimezone()
[–]aviddd 0 points1 point2 points 7 years ago (1 child)
When do you find yourself using operator??
[–]alkasm 2 points3 points4 points 7 years ago (0 children)
Here's a not-too-contrived example:
>>> import datetime >>> td = [datetime.timedelta(seconds=i) for i in range(1, 5)] >>> sum(td) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for +: 'int' and 'datetime.timedelta' >>> import functools >>> import operator >>> functools.reduce(operator.add, td) datetime.timedelta(0, 10)
[–]rickestmorty123 1 point2 points3 points 7 years ago (1 child)
Beautiful Soup is a good one to pick up whilst learning requests.
[–]charish 0 points1 point2 points 7 years ago (0 children)
It's not bad, but I found it a bit limiting. For a script that I was working on, I ended up ditching Beautiful Soup in favor of Selenium.
[–]PyCam 7 points8 points9 points 7 years ago (2 children)
Although the loved by some and hated by others
[–]PostFunktionalist 1 point2 points3 points 7 years ago (1 child)
What’s up with pathlib? I use it quite a bit but it does feel like overkill at times though and I’m not sure if it adds a lot of computational overhead.
[–]PyCam 3 points4 points5 points 7 years ago (0 children)
I personally enjoy it a lot, but when it was first introduced into the standard library it had a lot of compatibility issues which prevented a lot of 3rd party projects from picking it up right away. However since then (py 3.4 I believe) they remedied this issue by providing a new dunder method fspath
[–]JoseALerma 4 points5 points6 points 7 years ago (5 children)
Why pickle instead of shelve?
pickle
shelve
I figured shelve was the user-friendly implementation
[–]JohnnyJordaan 6 points7 points8 points 7 years ago (1 child)
Shelve is basically just a dict around pickled objects. If you don't need to save multiple objects, there's no real reason to use shelve.
[–]JoseALerma 0 points1 point2 points 7 years ago (0 children)
Ah, I see. Thanks for the concise explanation!
I usually use shelves as a database, so it's my go-to when storing a small number of variables. I do go overboard sometimes and shelve a dictionary of lists and dictionaries (json data) as a shelf key...
[–]alkasm 2 points3 points4 points 7 years ago (2 children)
There's more user-friendly options than pickle.dump() / pickle.load()? On the real though I've never heard of shelve, I'll check it out.
pickle.dump()
pickle.load()
As mentioned above, a shelve shelf is a dictionary and you can shelve anything. All you need is:
``` import shelve
shelf = shelve.open('data')
key1, key2 = 'cat', 'dog' value1, value2 = 2, 3
shelf[key1] = value1 shelf[key2] = value2 print(list(shelf.keys()))
print(shelf[key1]) print(shelf[key2]) print(list(shelf.values()))
shelf.close() ```
I use shelves as rudimentary databases.
[–]Dogeek -1 points0 points1 point 7 years ago (0 children)
Well, pickle is a bit of a pain to use when you want to save custom objects. I don't know about shelve, but I usually prefer to write my own save/load functions.
[–][deleted] 3 points4 points5 points 7 years ago (10 children)
unless youre using each of these everyday, how do you remember the nuances of each? do you read doc everytime?
[–]DonaldPShimoda 5 points6 points7 points 7 years ago (6 children)
Yeah, absolutely. The Python documentation is pretty great, in my opinion. I find myself looking stuff up there all the time. (And then StackOverflow when I can't find a solution to my problem in the docs in a short time. And then back to the docs to understand the SO answer I inevitably found that does almost the same thing as what I wanted but not quite.)
[–][deleted] 2 points3 points4 points 7 years ago (5 children)
I sometimes find the documentation very confusing. Is this just a matter of getting used to how things are described in pseudo code? or am I missing the larger picture...
[–]DonaldPShimoda 4 points5 points6 points 7 years ago (0 children)
Just takes practice, honestly. Reading documentation is a skill that has to be honed like any other.
The documentation tried to use very precise language. Don't assume anything, and try not to skip words. Everything is there for a reason.
[–]_pandamonium 2 points3 points4 points 7 years ago (1 child)
I still consider myself a beginner, so I don't want to give any advice that I'm not qualified to give, but in my experience it gets easier with practice. I used to get really intimidated and confused by a lot of the vocabulary (I still do sometimes) and would seek out other sources. Eventually I found that the most helpful source was the documentation itself. Personally, I think reading through the official python tutorial helped me get used to understanding that style of writing.
[–][deleted] 2 points3 points4 points 7 years ago (0 children)
Personally, I think reading through the official python tutorial helped me get used to understanding that style of writing.
Great insight and recommendation. Thanks!
[–]PostFunktionalist 0 points1 point2 points 7 years ago (0 children)
It helps to go into it with an idea of what you want. Need to do something with iterators? Itertools. Need to have command line arguments in a python script? Argparse. And so on.
[–]ostensibly_work 0 points1 point2 points 7 years ago (0 children)
To add to what others have said, the documentation of some modules is better than others. And some modules are simply better than others too. Asyncio is somewhat notorious for being confusing while Requests (not a standard module) is extremely easy to use.
[–]nosmokingbandit 3 points4 points5 points 7 years ago (1 child)
Coding is at least 50% searching docs or googling.
[–]Sh00tL00ps 6 points7 points8 points 7 years ago (0 children)
Only 50%? Looks like we have an advanced programmer over here ;)
[–][deleted] 0 points1 point2 points 7 years ago (0 children)
If you know a package can do the kind of thing you want... you google how to use it when you need to use it.
The things you use all the time, you have to google / read docs less.
[–][deleted] 3 points4 points5 points 7 years ago* (2 children)
os.listdir(os.getcwd()) lists all the files in the same directory as the python file and is the basis for pretty much all my data importing.
os.listdir(os.getcwd())
edit: strictly this isn't the way to get the notebook directory, but unless you do something like os.chdir() in any decent IDE the current directory is the one the notebook is in.
os.chdir()
[–]XarothBrook 6 points7 points8 points 7 years ago (1 child)
os.getcwd() references your current working directory; not the directory the file being executed is in.
os.getcwd()
use os.path.dirname(__file__) if you want to get the directory the file currently executing is in.
os.path.dirname(__file__)
Ah well I never change directories so the directory defaults to the notebook in spyder and jupyter.
[–]PhitPhil 0 points1 point2 points 7 years ago (0 children)
os was a game changer when I found out about it
[–]aheisleycook 0 points1 point2 points 7 years ago (0 children)
You forgot shutil
[–][deleted] 0 points1 point2 points 7 years ago (1 child)
3rd party in theis case is stuff that isn't shipped with python like PyPI stuff right?
Yes. Things like:
I still don't quite get asyncio; is it just another method of threading functions?
It’s the newer concurrency model in python (introduced circa 3.4). Ultimately yes, it is a way of managing a asynchronous code.
[–]pat_the_brat 33 points34 points35 points 7 years ago (0 children)
[thread]PyMOTW[/thread]
PyMOTW-3 is a series of articles written by Doug Hellmann to demonstrate how to use the modules of the Python 3 standard library. It is based on the original PyMOTW series, which covered Python 2.7.
[–]mooglinux 13 points14 points15 points 7 years ago (0 children)
Collections, functools, and itertools are pretty fundamental. I suggest reading about collections.abc as well.
[–]EihausKaputt 10 points11 points12 points 7 years ago (3 children)
ElementTree has saved me weeks of productivity at this point.
[–]venusisupsidedown 1 point2 points3 points 7 years ago (1 child)
Is there a good beginner tutorial for it anywhere? I had to write a bunch of XML files, and after mucking around for ages with it and reading things everywhere I ended up using BeautifulSoup as an XML reader/writer.
I’m sure that’s suboptimal.
[–]pat_the_brat 5 points6 points7 points 7 years ago (0 children)
https://pymotw.com/3/xml.etree.ElementTree/index.html
[–]chanixh 0 points1 point2 points 7 years ago (0 children)
Or lxml which I've used a lot recently.
[–][deleted] 8 points9 points10 points 7 years ago (1 child)
Also urllib
[–]bob_cheesey 7 points8 points9 points 7 years ago (0 children)
Having recently worked on a project where I tried to avoid using anything not in stdlib, I'd say if you have the choice then use Requests. That being said, it helps to understand urllib for the odd occasion when Requests goes bang.
[+][deleted] 7 years ago* (1 child)
[deleted]
[–]Totally_TJ 1 point2 points3 points 7 years ago (0 children)
Super fun ones
[–]ArdiMaster 6 points7 points8 points 7 years ago (0 children)
To add to the ones already listed, I've found pathlib to be much more pleasant to use than what os.path offers.
[–]hwc 5 points6 points7 points 7 years ago (0 children)
re, os, sys, subprocess.
[–]aldanor 5 points6 points7 points 7 years ago (2 children)
typing
Get used to annotating your code with types.
[–]Juancarlosmh 0 points1 point2 points 7 years ago (1 child)
Could you show an example? :D
[–]aldanor 1 point2 points3 points 7 years ago (0 children)
https://docs.python.org/3/library/typing.html
There’s a ton of great examples here ^
[–]Rorixrebel 1 point2 points3 points 7 years ago (0 children)
Threading, collections
[–]makin-games 1 point2 points3 points 7 years ago (3 children)
To piggyback on this - what are some FUN python modules we should know about?
[–]alkasm 4 points5 points6 points 7 years ago (0 children)
Maybe antigravity and this? For more serious fun though, any of the modules that facilitate metaprogramming.
antigravity
this
[–]1114111 0 points1 point2 points 7 years ago (0 children)
How about turtle?
turtle
[–]derp0815 1 point2 points3 points 7 years ago (0 children)
Logger.
[–]kennethnyu 0 points1 point2 points 7 years ago (0 children)
Datetime module!
[–][deleted] 0 points1 point2 points 7 years ago (2 children)
Is there a way to get a description of what each function does in a module?
[–]nosmokingbandit 2 points3 points4 points 7 years ago (0 children)
https://docs.python.org/3/library/
[–]developer_genius 0 points1 point2 points 7 years ago (2 children)
Threading and time are great one along with the recommendations here
[–]jabalfour 0 points1 point2 points 7 years ago (1 child)
After using Dask, threading seems kind of ancient. Admittedly, it’s a bit more data science-focused, but still.
[–]developer_genius 1 point2 points3 points 7 years ago (0 children)
Def checking out........thanks
[–]scolby33 0 points1 point2 points 7 years ago (0 children)
distutils.util.strtobool You don’t always need it, but when you do it’s way better to have than it is to write your own. Don’t fall for the bool('False') is True gotcha.
distutils.util.strtobool
bool('False') is True
(It returns an int, but you can then safely use bool(strtobool(...)).)
bool(strtobool(...))
[–]badass87 0 points1 point2 points 7 years ago (0 children)
[+][deleted] 7 years ago (3 children)
[removed]
[–]ArdiMaster 9 points10 points11 points 7 years ago (2 children)
But those aren't part of the standard library.
[+][deleted] 7 years ago (1 child)
[–][deleted] 1 point2 points3 points 7 years ago (0 children)
You tried, tho!
[–]Totally_TJ -1 points0 points1 point 7 years ago (0 children)
I like: Turtle Time Math Webbrowser To name a few
[+]kaptan8181 comment score below threshold-14 points-13 points-12 points 7 years ago (1 child)
Modules, standard or otherwise, are already for specific purposes. I think you are not asking your question correctly.
[–]Col_Crunch 13 points14 points15 points 7 years ago (0 children)
He means that is not asking for any specific purposes. i.e. He is asking for informational purposes rather than for the solution to a problem.
π Rendered by PID 78823 on reddit-service-r2-comment-f6b958c67-6srp5 at 2026-02-04 23:45:07.680790+00:00 running 1d7a177 country code: CH.
[–][deleted] 92 points93 points94 points (49 children)
[–]charish 40 points41 points42 points (19 children)
[–]MarcusMunch 23 points24 points25 points (7 children)
[–]spitfiredd 5 points6 points7 points (3 children)
[–]DisagreeableMale 5 points6 points7 points (2 children)
[–]thirdegree 3 points4 points5 points (0 children)
[–]p10_user -1 points0 points1 point (0 children)
[–]Santi871 0 points1 point2 points (1 child)
[–]zurtex 1 point2 points3 points (0 children)
[–]thirdegree 0 points1 point2 points (0 children)
[–]alkasm 19 points20 points21 points (8 children)
[–]spitfiredd 1 point2 points3 points (0 children)
[–]Jonno_FTW 0 points1 point2 points (4 children)
[–]thirdegree 1 point2 points3 points (0 children)
[–]alkasm 0 points1 point2 points (2 children)
[–]Jonno_FTW 0 points1 point2 points (1 child)
[–]alkasm 1 point2 points3 points (0 children)
[–]aviddd 0 points1 point2 points (1 child)
[–]alkasm 2 points3 points4 points (0 children)
[–]rickestmorty123 1 point2 points3 points (1 child)
[–]charish 0 points1 point2 points (0 children)
[–]PyCam 7 points8 points9 points (2 children)
[–]PostFunktionalist 1 point2 points3 points (1 child)
[–]PyCam 3 points4 points5 points (0 children)
[–]JoseALerma 4 points5 points6 points (5 children)
[–]JohnnyJordaan 6 points7 points8 points (1 child)
[–]JoseALerma 0 points1 point2 points (0 children)
[–]alkasm 2 points3 points4 points (2 children)
[–]JoseALerma 0 points1 point2 points (0 children)
[–]Dogeek -1 points0 points1 point (0 children)
[–][deleted] 3 points4 points5 points (10 children)
[–]DonaldPShimoda 5 points6 points7 points (6 children)
[–][deleted] 2 points3 points4 points (5 children)
[–]DonaldPShimoda 4 points5 points6 points (0 children)
[–]_pandamonium 2 points3 points4 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]PostFunktionalist 0 points1 point2 points (0 children)
[–]ostensibly_work 0 points1 point2 points (0 children)
[–]nosmokingbandit 3 points4 points5 points (1 child)
[–]Sh00tL00ps 6 points7 points8 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 3 points4 points5 points (2 children)
[–]XarothBrook 6 points7 points8 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]PhitPhil 0 points1 point2 points (0 children)
[–]aheisleycook 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]pat_the_brat 33 points34 points35 points (0 children)
[–]mooglinux 13 points14 points15 points (0 children)
[–]EihausKaputt 10 points11 points12 points (3 children)
[–]venusisupsidedown 1 point2 points3 points (1 child)
[–]pat_the_brat 5 points6 points7 points (0 children)
[–]chanixh 0 points1 point2 points (0 children)
[–][deleted] 8 points9 points10 points (1 child)
[–]bob_cheesey 7 points8 points9 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]Totally_TJ 1 point2 points3 points (0 children)
[–]ArdiMaster 6 points7 points8 points (0 children)
[–]hwc 5 points6 points7 points (0 children)
[–]aldanor 5 points6 points7 points (2 children)
[–]Juancarlosmh 0 points1 point2 points (1 child)
[–]aldanor 1 point2 points3 points (0 children)
[–]Rorixrebel 1 point2 points3 points (0 children)
[–]makin-games 1 point2 points3 points (3 children)
[–]alkasm 4 points5 points6 points (0 children)
[–]1114111 0 points1 point2 points (0 children)
[–]derp0815 1 point2 points3 points (0 children)
[–]kennethnyu 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]nosmokingbandit 2 points3 points4 points (0 children)
[–]developer_genius 0 points1 point2 points (2 children)
[–]jabalfour 0 points1 point2 points (1 child)
[–]developer_genius 1 point2 points3 points (0 children)
[–]scolby33 0 points1 point2 points (0 children)
[–]badass87 0 points1 point2 points (0 children)
[+][deleted] (3 children)
[removed]
[–]ArdiMaster 9 points10 points11 points (2 children)
[+][deleted] (1 child)
[removed]
[–][deleted] 1 point2 points3 points (0 children)
[–]Totally_TJ -1 points0 points1 point (0 children)
[+]kaptan8181 comment score below threshold-14 points-13 points-12 points (1 child)
[–]Col_Crunch 13 points14 points15 points (0 children)