-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresources.py
135 lines (104 loc) · 5.01 KB
/
resources.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
'''Resources'''
# Python philosophy
# -----------------------------------------------------------------------------
import this
# Good explanations
# -----------------------------------------------------------------------------
# Python Docs- https://docs.python.org/3/
# Built-ins: https://www.programiz.com/python-programming/methods/built-in
# http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/
# When looking for code
# -----------------------------------------------------------------------------
# PyPI - https://pypi.python.org/pypi
# Github - https://github.com/trending?l=python
# Active State - http://code.activestate.com/recipes/langs/python/
# help()
# -----------------------------------------------------------------------------
# In the python interpreter, use the help function to get information on a
# module or built-in function, or run the help utility to get information on
# keywords, symbols, topics, modules and built-in functions. For example:
help() # Welcome to Python 3.6's help utility!
keywords # lists all keywords
symbols # lists all symbols
topics # lists all help topics
modules # list all modules
builtins # lists all built-in functions and exceptions
yield # describes the yield statement
@ # describes decorators
DEBUGGING # provides information on 'pdb' the python debugger
random # provides information on the random standard library module
print # provides information in the print built-in function
ValueError # provides information on the ValueError exception
# you don't have to enter the help utility to get help either, you can pass
# the name of a function or module directly (this method doesn't work for
# keywords, symbols or topics).
help(print)
help(ValueError)
import random
help(random)
# you can also ask for specific help on a method or class such as:
help(list.extend)
help(str.translate)
help(set.difference)
help(datetime.datetime)
# dir()
# -----------------------------------------------------------------------------
# The built-in dir function is an easy way to grab a list of all the attributes
# available inside an object (i.e., its methods and simpler data items). It can
# be called on any object that has attributes, including imported modules and
# built-in types, as well as the name of a data type.
import random
dir(random)
# [..., 'betavariate', 'choice', 'choices', 'expovariate', 'gammavariate',
# 'gauss', 'getrandbits', 'getstate', 'lognormvariate', 'normalvariate',
# 'paretovariate', 'randint', 'random', 'randrange', 'sample', 'seed',
# 'setstate', 'shuffle', 'triangular', 'uniform', 'vonmisesvariate',
# 'weibullvariate']
# To find out what attributes are provided in objects of built-in types, run
# dir on a literal or an existing instance of the desired type. For example,
# to see list, string, dict attributes, you can pass empty objects:
dir(list)
# [..., 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop',
# 'remove', 'reverse', 'sort']
dir(str)
# [..., 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith',
# 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha',
# 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable',
# 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip',
# 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust',
# 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith',
# 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']'
dir(dict)
# [..., 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem',
# 'setdefault', 'update', 'values']
dir(tuple)
# [..., 'count', 'index']
dir(set)
# [..., 'add', 'clear', 'copy', 'difference', 'difference_update', 'discard',
# 'intersection', 'intersection_update', 'isdisjoint', 'issubset', 'issuperset',
# 'pop', 'remove', 'symmetric_difference', 'symmetric_difference_update',
# 'union', 'update']
# Docstrings
# -----------------------------------------------------------------------------
# Builtins, modules and more have their own docstrings, which can also provide
# information. For example:
print(print.__doc__)
import random
print(random.__doc__)
print(random.choice.__doc__)
# HTML PyDoc
# -----------------------------------------------------------------------------
# Another way to view help similar to the help() and docstrings is to use
# the built-in PyDoc HTML by running this command in terminal:
# python3 -m pydoc -b
# The interesting thing about this is, it will include any python modules
# (.py files) it finds from the current directory you were in when you
# launched it. It's actually pretty great!
# View the source code
# -----------------------------------------------------------------------------
# If you want to take a look at the actual file to read the comments and
# docstring there, you can use the __file__ magic method to show you the
# path to where this module lives:
import os
print(os.__file__)
# /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/os.py