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

Day 5

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

In [1]:
import atexit
In [52]:
print(atexit.__doc__) 
allow programmer to define multiple exit functions to be executedupon normal program termination.

Two public functions, register and unregister, are defined.

In [53]:
# 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
In [12]:
test_exit
Out[12]:
<module 'atexit' (built-in)>
In [15]:
print(atexit.register.__doc__)
register(func, *args, **kwargs) -> func

Register a function to be executed upon normal program termination

    func - function to be called at exit
    args - optional arguments to pass to func
    kwargs - optional keyword arguments to pass to func

    func is returned to facilitate usage as a decorator.
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.

In [20]:
import calendar

calendar.__doc__
Out[20]:
'Calendar printing functions\n\nNote when comparing these calendars to the ones printed by cal(1): By\ndefault, these calendars have Monday as the first day of the week, and\nSunday as the last (the European convention). Use setfirstweekday() to\nset the first day of the week (0=Monday, 6=Sunday).'

uhhh how do I use it tho

In [21]:
calendar.February
Out[21]:
2

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

In [24]:
calendar.January
calendar.February
calendar.March
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-24-62efdf796470> in <module>
      1 calendar.January
      2 calendar.February
----> 3 calendar.March

AttributeError: module 'calendar' has no attribute 'March'
In [25]:
calendar.January
calendar.February
Out[25]:
2

uh weird... I don't see March in the functions.

oh dudes/people/whathaveyou here's a cool tutorial on the thing

In [26]:
hc = calendar.HTMLCalendar()
print(hc.formatmonth(2019, 7))
<table border="0" cellpadding="0" cellspacing="0" class="month">
<tr><th colspan="7" class="month">July 2019</th></tr>
<tr><th class="mon">Mon</th><th class="tue">Tue</th><th class="wed">Wed</th><th class="thu">Thu</th><th class="fri">Fri</th><th class="sat">Sat</th><th class="sun">Sun</th></tr>
<tr><td class="mon">1</td><td class="tue">2</td><td class="wed">3</td><td class="thu">4</td><td class="fri">5</td><td class="sat">6</td><td class="sun">7</td></tr>
<tr><td class="mon">8</td><td class="tue">9</td><td class="wed">10</td><td class="thu">11</td><td class="fri">12</td><td class="sat">13</td><td class="sun">14</td></tr>
<tr><td class="mon">15</td><td class="tue">16</td><td class="wed">17</td><td class="thu">18</td><td class="fri">19</td><td class="sat">20</td><td class="sun">21</td></tr>
<tr><td class="mon">22</td><td class="tue">23</td><td class="wed">24</td><td class="thu">25</td><td class="fri">26</td><td class="sat">27</td><td class="sun">28</td></tr>
<tr><td class="mon">29</td><td class="tue">30</td><td class="wed">31</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td><td class="noday">&nbsp;</td></tr>
</table>

July 2019
MonTueWedThuFriSatSun
1234567
891011121314
15161718192021
22232425262728
293031    

The cool thing about Jupyter Notebook is that if you embed html in a markdown cell, you get it rendered. pretty neat huh?

In [57]:
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)
Operator interface.

This module exports a set of functions implemented in C corresponding
to the intrinsic operators of Python.  For example, operator.add(x, y)
is equivalent to the expression x+y.  The function names are those
used for special methods; variants without leading and trailing
'__' are also provided for convenience.
In [58]:
b = str(operator.add(5,4)) 

hmm..saw that coming didn't ya?

In [59]:
a = operator.concat('me','ow')
a
Out[59]:
'meow'
In [43]:
print(operator.attrgetter.__doc__) # better to use print 
attrgetter(attr, ...) --> attrgetter object

Return a callable object that fetches the given attribute(s) from its operand.
After f = attrgetter('name'), the call f(r) returns r.name.
After g = attrgetter('name', 'date'), the call g(r) returns (r.name, r.date).
After h = attrgetter('name.first', 'name.last'), the call h(r) returns
(r.name.first, r.name.last).
In [60]:
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
Out[60]:
operator.attrgetter('meow', '9')

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