-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstandard_library.py
54 lines (36 loc) · 1.2 KB
/
standard_library.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
#####
# STANDARD LIBRARY
#####
import sys
# print(sys.path) # See the current sys path
# What will happen if we try to import a module from a different directory?
# Python can't find it
# We must add the path
sys.path.append('~/ale/Desktop/my_modules')
# print(sys.path)
# Or we can add to the PATH environment variable (Different from Linux to Windows)
# ---------- Linux ----------
# nano ~/.bash_profile
# export PYTHONPATH="~/ale/Desktop/my_modules"
# Standard Library is one of the best resources already written
# EXAMPLE
# Work with random module
import random
courses = ['Art', 'Maths', 'History', 'CS']
random_course = random.choice(courses)
print(random_course + '\n')
# Work with math module
import math
rads = math.radians(90) # pi/2
print('{}\n'.format(math.sin(rads))) # 1
# Work with time and date module
import datetime
import calendar
today = datetime.date.today()
print(today) # Today's date
print('{}\n'.format(calendar.isleap(2019))) # Leap year?
# Work with os module
import os
print(os.getcwd()) # Current working directory
print(os.__file__) # Where the entire standard library is located
# --------------------> <-------------------- #