guess what we're going to do today.
I found a list of standard library things and I'm going to import them and see what they might do. I might actually get bored of this because there are a lot. You'll be learning a lot, I'll be learning a lot. I'm using the phrase 'a lot' a lot. What could go wrong?
It's 2019-07-28 00:17:26.844698 and welcome to
sometimes the blog post comes after the day, that's just how it be
what is the standard library? Great question.
Python, the programming language I use is packed full of fun things right off the bat. On my other posts you may see "import" at some point. That's importing some files of code that I don't have. I can then use that pile of code in my own workflow.
It's like this. You're at a crafts person's table. It's your table. It's really dope. You have all of these tools but you need a hammer. You always keep the really good hammer in the garage though.
So you must import it. (not saying here that you "export" things ever, only saying what I'm saying).
import hammer
now you can use the hammer on things.
hammer = Hammer()
nail = 'nail'
nail.hammer
Try running that code.
Tell me what happens.
Super bad analogy
import atexit
print(atexit.__doc__)
# wow, isn't that neat? (great spelling too) look how easy it is to learn about stuff. that is some good documentation too.
# I am just going to literally print all of these out and read them for me. So you don't have to stay.
test_exit = atexit
test_exit
print(atexit.register.__doc__)
from atexit import register
def easy_funk():
print('hello cruel world')
test_decorator=register(easy_funk)
print('test string')
# this import prints something on end of program execution
this little script I wrote to test out the atexit module and ran it from the command line. it prints out:
hello cruel world
test string
and the funny part was is that I didn't even call test_decorator. I just initialized it (this means it's only getting defined, the button isn't being pressed if that makes sense)
oh my gosh there are so many. it's crazy. you should honestly try this out for me because I have a list that's a mile long. Just do what I did there. That works. Let me do one or two more to see what I have here.
import calendar
calendar.__doc__
uhhh how do I use it tho
calendar.February
whoa
so you have to know I work with jupyter notebooks (maybe you thought I was just dope at html but notice how ungreat my styling is. I can use shift+tab to see autofinish solutions. It's like seeing what other people have searched through google but ALL the options.
it's all about the environment people. trust me.
this is serious. now I have to test all the things
calendar.January
calendar.February
calendar.March
calendar.January
calendar.February
uh weird... I don't see March in the functions.
oh dudes/people/whathaveyou here's a cool tutorial on the thing
hc = calendar.HTMLCalendar()
print(hc.formatmonth(2019, 7))
July 2019 | ||||||
---|---|---|---|---|---|---|
Mon | Tue | Wed | Thu | Fri | Sat | Sun |
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
The cool thing about Jupyter Notebook is that if you embed html in a markdown cell, you get it rendered. pretty neat huh?
import operator
print(operator.__doc__) # in all honesty I came back through and added this in places but doing this makes
# more readable (by 'doing this' I mean calling the print function on the method doc)
b = str(operator.add(5,4))
hmm..saw that coming didn't ya?
a = operator.concat('me','ow')
a
print(operator.attrgetter.__doc__) # better to use print
f = operator.attrgetter(a,b)
f # I turned b into a string later on. writing code in jupyter notebooks is like changing the course of history
woah. freaky.
Alright ya'll. I just showed anyone who has read this and can type into a python interpreter a crap ton about how to learn stuff. Honestly, if docs returns an error, you probably shouldn't use it. I'm a little intrigued to say the least about there note be a .March
method in the calendar
module so I'm definitely looking into that a little bit more.
Peaches