-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
412 lines (351 loc) · 6.92 KB
/
test.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
'test doc'
cc = -1
a = 10
b = a + 1
c = b - 2
d = c * 2
e = c / 3
g = 3.5
x, y = 113, 224
if a*0:
h = 10
elif b:
h = 15
else:
h = 20
i = 0
j = a
while j:
j = j - 1
i = i + 1
pass
if not j > 10:
break
else:
i = 1
def f1(a, b, c):
return a + b
s= f1(**{'a':1, 'b':2, 'c':5})
class F:
'OhThisIsDoc'
def __init__(self):
self.gg = 90
def hi(self):
self.d = 99
print('hi')
a = b
return 1023
class Foo(F):
a = 10
def __init__(self):
self.b = 1022
self.f = F()
def __str__(self):
return 'Foo instance:'
def __len__(self):
return 10
def __eq__(self, v):
print('eeeeeeeee')
return v.c == 12
def go(self):
self.c = 20
print('go')
return self
def say(a):
return a
@property
def A(self):
print('property self:', self)
return self.f
@A.setter
def A(self, v):
print('property set:', v)
self.b = v
f = Foo()
print('lenf', len(f))
gg2 = f.A.gg
property1 = f.A
f2 = Foo()
f2.c = 10
if f == f2:
print('equal2')
foo = Foo()
print(foo)
ee = foo.hi()
foo.c = 201
foo.a = 20
Fa = Foo.a
fa = foo.a
print('fa', Fa, fa)
foo.go()
foo.c = 202
fc = foo.c
print 1, 2, 3
print('fc', fc)
fhi = foo.hi()
fd = foo.d
a, b, c = (1, 2, 3)
#from mod import *
#from mod import mb
import ma
try:
ta = 109
raise 1002
except int, i:
teai = 2399
except Foo, f:
teafoo = 199
except F, f:
teaf = 299
except:
tea = 99
else:
tel = 89
finally:
tef = 78
ecpp = Exception
def wf2():
return 6633
def wrap(f):
print('wrap....')
return f
def wrap2(f):
print('wrap2....')
return wf2
@wrap2
@wrap
def wf():
return 1122334
testD = wf()
testN = None
testtuple = (1, 2, 3, 4, 2)
testtupcount = testtuple.index(4)
testlen = len('1222')
tests1 = 'abcdefg'
tests2 = tests1.upper()
tests3 = tests2.lower()
tests3 = tests2.lower()
xx = tests3[3:100]
print(xx)
fooname = Foo.__name__
lista = [1, 2, 3, 4]
listb = [5, 6, 5]
listb.append(7)
listb.extend(lista)
listc = lista + listb
listalen = len(lista)
listb.insert(0, 100)
listb.insert(2, 102)
listb.insert(10, 110)
listb.insert(120, 120)
listb.pop(1)
listb.remove(110)
lista.reverse()
def cmpf(a, b):
return b - a
def keyf(a):
return a
listb.sort(None, keyf)
print(listb)
listindex= listb.index(6)
listcount= listb.count(5)
listtuple = (1, 2, 3, 4)
listtuple = (1, 2, 3, 4)
testdict2= {k:k for k in listtuple}
testdict2['a'] = 'aaa'
testdict3 = testdict2[3]
testdict4 = testdict2['a']
sdump = `listtuple`
print('sdump', sdump)
#listtuple[1] = 2
lambda1 = lambda x : x + 1
lambda2 = lambda1(120)
testdict5 = testdict2.items()
testdict2.pop(3)
testdict6 = testdict2.items()
for k, v in testdict2.items():
print(k, v)
for k in testdict2:
print('xxxx', k, testdict2[k])
testdict7 = testdict2.copy()
testdict7.clear()
testdict7 = dict.fromkeys(listtuple, 122)
testdict8 = testdict7.get(12, 13)
testdict9 = testdict7.has_key(12)
testdict10= testdict7.keys()
testdict7.popitem()
testdict7.update({3:333, 1:1111})
testdict11 = testdict7.values()
for m, n in testdict7.iteritems():
print('iter', m, n)
def closure1():
'closure doc'
def closure2():
print('closure2', mm)
def closure3():
print('closure3', mm)
return mm
return closure3
mm = 101
return closure2
print('f.b1', f.b)
del testdict11
del f.b
del testdict2[1]
del listb[1]
foodoc = f.__doc__
closuredoc = closure1.__doc__
testdoc = __doc__
def fglobal():
global gX
print('gX', gX)
gX = 1010
gX = 1009
fglobal()
e1 = BaseException(1, 2, 'a')
print('e1', e1)
iAdd1 = 100
iAdd1 += 10
iAdd1 *= 2
iAdd1 %= 3
n1 = 0X12
n2 = -n1
n3 = 1 << 4
list21 = '''ss'
gg'''
print(list21)
#import weakref
weakref = __import__('weakref')
ref1 = weakref.ref(foo)
del foo
ref2 = ref1()
#ref3 = foo.c
import time
time1 = time.time() - 3600
time2 = time.localtime(time1 )
print(time2)
time3 = time.mktime(time2)
print(time1, time3)
from time import time as time4
import datetime
dt1 = datetime.datetime(2016, 9, 12, 7, 8, 12)
dt2 = dt1.strftime("%Y-%m-%d %H:%M:%S")
dt3 = datetime.datetime.now()
print(dt1)
print(dt2)
print(dt3.strftime("%Y-%m-%d %H:%M:%S"))
dt4 = dt1.date()
print(dt4)
dt5 = datetime.date.today()
print(dt5)
dt6 = datetime.datetime.strptime("2016-10-17 18:20:10", "%Y-%m-%d %H:%M:%S")
print(dt6)
dt7 = datetime.timedelta(3)
print(dt7)
dt8 = dt6 - dt7
dt9 = dt8 - dt6
print(dt9)
dt10 = dt8.timetuple()
print(dt10)
dt11 = datetime.datetime.fromtimestamp(1421077403.0)
print(dt11)
dt12 = dt6.weekday()
print(dt12)
dt13 = dt6.isoweekday()
print(dt13)
dt14 = dt3.isoformat()
print(dt14)
dt15 = dt5 - dt4
print(dt15)
dt16 = dt4 + dt15
print(dt16)
dt17 = dt16.weekday()
print(dt17)
dt18 = dt16.isoweekday()
print(dt18)
dt19 = dt16.isoformat()
print(dt19)
import json
import StringIO
output = StringIO.StringIO()
output.write('First line.')
contents = output.getvalue()
print(contents)
testrange = range(0, 10)
import math
ceil1 = math.ceil(3.4)
print(ceil1)
floor1 = math.floor(5.6)
print(floor1)
acos1 = math.acos(0.3)
print(acos1)
strmod1 = 'abc%-3d,%d'%(12, 8)
print('strmod1', strmod1)
import random
rand1 = random.random()
print('rand1', rand1)
rand2 = random.uniform(10,20)
print('rand2', rand2)
rand3 = random.randint(10,20)
print('rand3', rand3)
listrand = [1,2, 3]
rand4 = random.choice(listrand)
print('rand4', rand4)
rand5 = random.shuffle(listrand)
print('listrand-2', listrand)
rand6=random.sample(listrand,2)
print('rand6', rand6)
file2 = open("ma.py", "r")
print('file2', file2)
file2_1 = file2.readline()
print('file2_1', file2_1)
file3 = file2.read(5)
print('file3', file3)
file2.close()
print('file2', file2)
with open("ma.py") as f:
file4 = f.read()
print('file4', file4)
import struct
print('structlen1', len(struct.pack('1s', 'a')))
struct1 = struct.pack('hhiqb', 1, 1, 2, 3, 4)
print('struct1', len(struct1))
struct2 = struct.unpack('hhiqb', struct1)
print('struct2', struct2)
struct1 = len(struct1)
import json
json1 = {'b':[1,2.3,3,'abc', [3, 4], {'a':123, 'b':False, 'c':None}]}
with open("json.txt", "wb") as f:
json.dump(json1, f)
with open("json.txt", "r") as f:
jsonload = json.load(f)
print('jsonload', jsonload)
json2 = json.dumps(json1)
print('json2', json2)
json3 = json.loads(json2)
print('json3', json3)
import platform
print('*'*20, platform.system())
import sys
argv = sys.argv
print('sys.argv', argv)
import os
getcwd = os.getcwd()
print('getcwd', getcwd)
listdir = os.listdir(os.getcwd())
print('listdir', listdir)
os.remove('json.txt')
os.system('pwd')
split = os.path.split('C:\\Python25\\abc.txt')
print('split', split)
isdir = os.path.isdir(os.getcwd())
print('isdir', isdir)
isfile = os.path.isfile(os.getcwd())
print('isfile', isfile)
basename = os.path.basename('c:\\Python\\a.txt')
print('basename', basename)
dirname = os.path.dirname('c:\\Python\\a.txt')
print('dirname', dirname)
thrift_spec = (
)
print(thrift_spec)