-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
231 lines (203 loc) · 5.14 KB
/
main.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# person_data = ["John", "Smith", 23, "programmer"]
# user_name, user_surname, user_age, user_occupation = person_data
# print user_age
# def countxz():
# f = open(r'c:/file.txt')
# text = f.readlines()
# print type(text), 'file context: ', text
# for i in text:
# print i
# if i == 'login: fdsfsdf\n':
# print 'wow'
# value1, value2, value3, value4 = text
# print "VALUES:", value1, value2, value3, value4
# list_value1 = value1.split()
# login, login_value = list_value1
# true_login = login[:-1]
# print true_login,'is', login_value
# return 1
# print countxz()
# login, value1, passwd, value2, param, value3, time, value4 = textlist
# print login, value1
# for i in text:
# k = 0
# k +=1
# # print k
# print i
# for i in text:
# i = (n, i[:])
# data.append(i)
# n += 1
# # enumerate(i)
# # tmp.append(i)
# print data
# f.close()
# return data
# list1 = count()
# a = list1
# for i in a:
# print "a=", a
import os
# def folder():
# cwd = os.getcwd()
# print cwd
# print os.path.exists('main.py')
# print os.listdir('../../../')
# folder()
# def walk(dir):
# for name in os.listdir(dir):
# path = os.path.join(dir, name)
# if os.path.isfile(path):
# print path
# else:
# walk(path)
# walk('.')
# import os, sys
# def getlocaldata(sms,dr,flst):
# for f in flst:
# fullf = os.path.join(dr,f)
# if os.path.islink(fullf): continue # don't count linked files
# if os.path.isfile(fullf):
# sms[0] += os.path.getsize(fullf)
# sms[1] += 1
# else:
# sms[2] += 1
# def dtstat(dtroot):
# sums = [0,0,1] # 0 bytes, 0 files, 1 directory so far
# os.path.walk(dtroot,getlocaldata,sums)
# return sums
#
# report = dtstat('.')
# print report
# import os, sys, fnmatch
#
# mask = '*.py'
# pattern = 'import os'
#
# def walk(arg,dir,files):
# for file in files:
# if fnmatch.fnmatch(file,mask):
# name = os.path.join(dir,file)
# try:
# data = open(name,'rb').read()
# if data.find(pattern) != -1:
# print name
# except:
# pass
# os.path.walk('../../../../',walk,[])
# import threading
# import Queue
#
# class Worker(threading.Thread):
#
# def __init__(self, work_queue, word):
# super(Worker,self).__init__()
# self.work_queue = work_queue
# self.word = word
#
# def run(self):
# try:
# filename = self.work_queue.get()
# self.process(filename)
# finally:
# pass
#
# def process(self, filename):
# previous = "
# current=True
# with open(filename, "rb") as fh:
# while current:
# current = fh.readline()
# if not current: break
# current = current.decode("utf8", "ignore")
# if self.word in current :
# print("find {0}: {1}".format(self.word,filename))
# previous = current
#
# word = 'import'
# filelist = ['./file1.py','./file2.py','./file3.py']
# work_queue = Queue.Queue()
# for filename in filelist:
# work_queue.put(filename)
# for i in range(3):
# worker = Worker(work_queue, word)
# worker.start()
# import time
#
# loop_count = 1000000
#
# def method1():
# from array import array
# char_array = array('c')
# for num in xrange(loop_count):
# char_array.fromstring(`num`)
# return char_array.tostring()
#
#
# def method2():
# str_list = []
# for num in xrange(loop_count):
# str_list.append(`num`)
# return ''.join(str_list)
#
# def method3():
# from cStringIO import StringIO
# file_str = StringIO()
# for num in xrange(loop_count):
# file_str.write(`num`)
# return file_str.getvalue()
#
# def method4():
# return ''.join([`num` for num in xrange(loop_count)])
#
# list = method4()
# print list
# # for i in list:
# # print i
#
# t1 = time.time()
# method1()
# t2 = time.time()
# print "\t%.1f" % ((t2 - t1))
# method2()
# t3 = time.time()
# print "\t%.1f" % ((t3 - t2))
# method3()
# t4 = time.time()
# print "\t%.1f" % ((t4 - t3))
# method4()
# t5 = time.time()
# print "\t%.1f" % ((t5 - t4))
# def f(x):
# for y in xrange(2, x):
# print x, '%', y
# if x % y == 0: return 0
# return 1
#
# print filter(f, xrange(2, 1000))
# seq1 = [1, 2, 3]
# seq2 = [4, 5, 6]
# for i, y in map(None, seq1, seq2):
# print i, y
class Tree(object):
def __init__(self, kind, height):
self.kind = kind
self.age = 0
self.height = height
def info(self):
print ("{} years old {}. {} meters high.".format(self.age, self.kind, self.height))
def grow(self):
self.age += 1
self.height += 0.5
class FruitTree(Tree):
# def __init__(self, kind, height):
# self.kind = kind
# self.age = 0
# self.height = height
def give_fruits(self):
print ("Collected 20kg of {}s".format(self.kind))
tree_2 = FruitTree("apple", 0.7)
tree_2.info()
tree_2.grow()
tree_2.give_fruits()
tree_1.give_fruits()