-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMore on Modules.py
More file actions
69 lines (58 loc) · 1.93 KB
/
More on Modules.py
File metadata and controls
69 lines (58 loc) · 1.93 KB
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
#
# Hands on exercises # 4
# More on Modules - built in.
#
# Ross Alejandro A. Bendal
# Wednesday - June 19 2013 - 9:38
#
#
############################ RANDOM ###########################
import random
random.randint(0, 10) #randint picks two parameters one being the lowest and the second being the highest.
randomFloat = random.random() * 100 #random float, multiply by 100 to get the decimals up to the first.
userList = ['ross','doby','unix']
randomList = random.choice(userList) #picks random index on a list.
print randomList
############################ MATHS ############################
print'maths function'
import math
math.pi
math.sin(20)
math.degrees(3)
math.factorial(5)
math.sqrt(49)
math.exp(5)
############################# URL ###########################
print 'url'
import urllib2
url = urllib2.urlopen("http://google.com").read(100) #gets the first 100 characters of that website.
print url
############################# DATE TIME #####################
print 'date and time'
import datetime
from datetime import date
import time
time = date.fromtimestamp(time.time()) #converts the time.time() to a more readable
print time
newDate = time.strftime("%d/%m/%y") #changes the date format with strftume
print newDate
ad = date.fromordinal(10000) # gets the year after 1 ad. wtf.
print ad
############################# OPERATING SYSTEM ###############
print 'operating system'
import os
from os import path
path2 = path.exists("C:") #checks if a direcotry exists.
print path2
pathTime = path.getatime("C:") #checks the time it was modified
print pathTime
#pathBytes = path.getsize{"C:"} #shows the size of a directory in bytes.
pathJoin = path.join("C:", "users")
print pathJoin
############################### LAST TIPS ###########################
#assign the modules and functions in variables.
#random.random() will be:
ran = random.random #parenthesis will be in the variable
print ran() #parenthesis here
square = math.sqrt
print square(2)