forked from dabeaz-course/practical-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusing_portfolio.py
More file actions
77 lines (54 loc) · 1.21 KB
/
using_portfolio.py
File metadata and controls
77 lines (54 loc) · 1.21 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
70
71
72
73
74
75
76
77
import report
portfolio = report.read_portfolio('.\\Data\\portfolio.csv')
print(len(portfolio))
print(portfolio[0])
print(portfolio[1])
print(portfolio[0:3])
print('IBM' in portfolio)
print('YIT' in portfolio)
print(portfolio.total_cost)
holdings = portfolio.tabulate_shares()
print(holdings)
print(holdings.most_common(2))
for h in holdings:
print(h, holdings[h])
def stock_name(s):
return 1/s.price # reverse order
portfolio = list(portfolio)
portfolio.sort(key=stock_name)
for s in portfolio:
print(s)
print()
portfolio.sort(key=lambda s: s.price)
for s in portfolio:
print(s)
"""
class Box:
def __init__(self, x=5, y=5):
self.x = x
self.y = y
# def __getattribute__(self, name):
# if name == "x":
# return 'No access.'
# else:
# # print(dir(name))
# return self
@property
def foo(self):
return self.y
Box.g = 100
b = Box(y=333)
f = b.foo
print(b.x, b.g, f)
# print(Box.__dict__)
"""
"""
t = (10,20,30)
for i in range(len(t)):
print('i:',i)
print(t[:i], t[i]+i , t[i+1:])
print('t ennen:',t)
t = t[:i] + (t[i] + i,) + t[i+1:]
print('t jälkeen:',t)
print()
"""